{"id":18947620,"url":"https://github.com/yousafkhamza/asg-rolling-update","last_synced_at":"2026-04-11T18:04:18.987Z","repository":{"id":195965571,"uuid":"372328048","full_name":"yousafkhamza/ASG-rolling-update","owner":"yousafkhamza","description":"We have created an ASG oriented ansible-playbook with dynamic inventory and its helps to update git contents which if the currently available instances and you can use this manually or automate via Jenkins like (continues deployment) and who use the playbook it never needs to create instances unwanted.","archived":false,"fork":false,"pushed_at":"2021-07-11T09:12:09.000Z","size":71,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-01T01:19:53.355Z","etag":null,"topics":["ansible","asg","aws","jenkins","jenkins-pipeline","rolling"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yousafkhamza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-05-30T22:34:56.000Z","updated_at":"2021-09-10T06:35:19.000Z","dependencies_parsed_at":"2023-09-20T19:52:57.582Z","dependency_job_id":"720a77bb-0c2a-4b45-bfb8-62e86196649e","html_url":"https://github.com/yousafkhamza/ASG-rolling-update","commit_stats":null,"previous_names":["yousafkhamza/asg-rolling-update"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2FASG-rolling-update","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2FASG-rolling-update/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2FASG-rolling-update/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yousafkhamza%2FASG-rolling-update/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yousafkhamza","download_url":"https://codeload.github.com/yousafkhamza/ASG-rolling-update/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239946876,"owners_count":19723014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","asg","aws","jenkins","jenkins-pipeline","rolling"],"created_at":"2024-11-08T13:10:40.599Z","updated_at":"2026-04-11T18:04:18.955Z","avatar_url":"https://github.com/yousafkhamza.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ASG Rolling Update (Ansible + Jenkins)\n[![Builds](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger)\n\n---\n## Description\n\nI just try to a new explanation method for easy to convey my work and details. Basically, this is an ansible-playbook with ASG Rolling update and Create an AWS Infrastructure with (ELB + ASG + Security Group). Its automated with Jenkins.\n\n_Client Query_: I have an ELB (Elastic LoadBalancer) in amazon and that ELB under instances is registered from an ASG. Also, the developers are uploaded the site contents to the git, and the developers make updates on git (ELB git changes through user-data with git). So, that's very complicated each update time has to change the count of ASG but it's very annoying and expensive creates and removes instances unwanted is there any solution?\n\n_Answer_: We have created a ASG oriented ansible playbook with dynamic inventory and its help to update git contents which if the current available instances and you can use this manually or automate via jenkins like (continues deployment) and who use the playbook it never needs to create instances unwanted.\n\n---\n## Features\n- ASG Rolling updates through ansible-playbook (_Primary_)\n- Includs ELB + ASG + Security group infrastructure on this ansible-playbook\n- No need for hosts (Inventory file) for ASG under client servers. Because its work with Dynamic Inventory\n- Furthermore, I have included a test website with user-data for more clarification\n- Easy to handle and everyone can change the ASG (Count, Project_Name.. etc values)\n- No need to install any dependencies like boto and boto3 (Please note that if you have using Ansible 2.2+ and python 2.7)\n---\n## Pre-Requests\n- Install Ansible on your Master Machine\n- Create an IAM user role under your AWS account and please enter the values once the playbook running time\n##### Installation\n[Ansible2](https://docs.ansible.com/ansible/2.3/index.html) (For your reference visit [How to install Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html))\n##### IAM Role Creation\n[IAM Role Creation](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create.html)\n##### Ansible Modules used\n- [yum](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html) \n- [pip](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/pip_module.html)\n- [ec2-key](https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_key_module.html)\n- [copy](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html)\n- [ec2-group](https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_group_module.html)\n- [debug](https://www.google.com/search?q=debug+%2B+ansible\u0026rlz=1C1ONGR_enIN928IN928\u0026oq=debug+%2B+ansible\u0026aqs=chrome..69i57.5092j0j4\u0026sourceid=chrome\u0026ie=UTF-8)\n- [ec2_lc](https://docs.ansible.com/ansible/latest/collections/community/aws/ec2_lc_module.html)\n- [ec2_elb_lb](https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_elb_lb_module.html)\n- [ec2_asg](https://docs.ansible.com/ansible/latest/collections/community/aws/ec2_asg_module.html)\n- [ec2_instance_info](https://docs.ansible.com/ansible/latest/collections/community/aws/ec2_instance_info_module.html)\n- [add_host](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/add_host_module.html)\n- [git](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html)\n- [file](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html)\n- [pause](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/pause_module.html)\n---\n### How To Use\nAnsible Installation article is in pre-request section so please check out the pre-request section.\n```sh\namzon-linux-extras install -y ansible2\nyum install git -y\ngit clone https://github.com/yousafkhamza/ASG-rolling-update.git\ncd ASG-rolling-update\n\n---Please-Change Your-Credentials---\n\nansible-playbook main.yml\n```\n---\n## Architacture with Jenkins Automated\n\n- Architacture\n\n![alt text](https://i.ibb.co/TqsqVML/rolling-update.jpg)\n---\n## Behind the playbook\n_I just explained the primary thing ASG Rolling update and Which variables I used so if you have any further doubts please look at the YAML file complete._\n### ASG Rolling update (_Primary Code_)\n```sh\n# Dynmic Inventory Creation\n    - name: \"Task 07-Fetch ASG Created EC2 Details\"\n      ec2_instance_info:\n        aws_access_key: \"{{ access_key }}\"\n        aws_secret_key: \"{{ secret_key }}\"\n        region: \"{{ region }}\"\n        filters:\n          \"tag:aws:autoscaling:groupName\": \"{{ asg_status.auto_scaling_group_name }}\"      \u003c------- this is your ASG Name\n          instance-state-name: [ \"running\"]\n      register: asg_instances\n\n\n    - name: \"Task 08-Autoscale - Creating Dynamic Inventory Of Autoscaling EC2\"\n      add_host:                    \u003c---------- Creating Dynmic Inventory\n        name: \"{{ item.public_ip_address }}\"\n        groups: \"asg\"\n        ansible_host: \"{{ item.public_ip_address }}\"\n        ansible_port: 22\n        ansible_user: \"ec2-user\"\n        ansible_ssh_private_key_file: ansible.pem\n        ansible_ssh_common_args: \"-o StrictHostKeyChecking=no\"\n      with_items:\n        - \"{{ asg_instances.instances }}\"\n\n# Play 02-Dyanamic Inventory Rolling Update. (Dynamic Inventory Play starts)\n- name: \"Task Dynamic Inventory Play 09-ASG Rolling Update Start\"\n  hosts: asg          \u003c------------ host works with dynmic inventory (hosts)\n  become: true\n  serial: 1\n  gather_facts: False\n  vars_files:\n    - instance.vars\n  tasks:\n```\n\n### Used Variables:\n- asg.vars\n```sh\nenv: \"ansible_project\"  \u003c---------- ProjectName\nami: \"ami-0d5eff06f840b45e9\" \u003c---------- I used us-east-1 region so the AMI under us-east-1\nkey: \"ansible\" \u003c-------------- Creating A keypair for entering ASG under instances\nregion: \"us-east-1\" \u003c-------------- Region\nsg_name: sgroup  \u003c--------------- Security group were I used. \ntype: \"t2.micro\" \u003c---------------  Instance_type\ncount: \"2\" \u003c----------------- ASG Count\n```\n- cred.vars\n```sh\naccess_key: \"\u003cyour-access-key\u003e\"     \u003c------------------ Enter your IAM Access Key\nsecret_key: \"\u003cyour-secret-key\u003e\"     \u003c------------------ Enter your IAM Secret Key\n```\n---\n## Conclusion \n_This playbook is used for ASG rolling update with a website contents from git without recreate instances. Furthermore, I tried to create a additional AWS infrastructure with a (ELB + ASG + Lauch Configuration + Security Group) through Ansible. So, you guys please reffer the playbook for creating infrastructure and dynamic inventory works with localhost inventory_\n\n\n### ⚙️ Connect with Me\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"mailto:yousaf.k.hamza@gmail.com\"\u003e\u003cimg src=\"https://img.shields.io/badge/Gmail-D14836?style=for-the-badge\u0026logo=gmail\u0026logoColor=white\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://www.linkedin.com/in/yousafkhamza\"\u003e\u003cimg src=\"https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white\"/\u003e\u003c/a\u003e \n\u003ca href=\"https://www.instagram.com/yousafkhamza\"\u003e\u003cimg src=\"https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge\u0026logo=instagram\u0026logoColor=white\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://wa.me/%2B917736720639?text=This%20message%20from%20GitHub.\"\u003e\u003cimg src=\"https://img.shields.io/badge/WhatsApp-25D366?style=for-the-badge\u0026logo=whatsapp\u0026logoColor=white\"/\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyousafkhamza%2Fasg-rolling-update","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyousafkhamza%2Fasg-rolling-update","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyousafkhamza%2Fasg-rolling-update/lists"}