Jenkins – AWS – Ansible – Rolling Update of AMI – Part 2

As we have configured Job1 – AMI lets move to Job2 – UpdateCF. The temporary file with the AMI Id should be injected in to Job2 so that it can update cloud formation stack with the new image.


Now as we are going to use ansible I’ve placed the code in GitHub Repo.


Now in the Build section run ansible-playbook with the AMI Id generated from Job1 – AMI.


Shell script is : As you can see we are passing the AMIId = $AMI which is picked from temporary file.

echo "Running the UploadCF $AMI"

cd ansible

ansible-playbook -i inventory.txt cloudformation.yml --extra-vars "aws_access_key_id=xxxxxxxxxxxxx aws_secret_access_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxx AMIId=$AMI"

Lets have a look at Test Git repository.


This is the main snippet for cloudformation which picks the CF template from S3 and applies the parameters. If the Stack does not exists already then creates and if it exists then updates the stack.


cloudformation variables:




One thought on “Jenkins – AWS – Ansible – Rolling Update of AMI – Part 2

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s