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.

Jenkins_UpdateCF1

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

Jenkins_UpdateCF3.JPG

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

Jenkins_UpdateCF4.JPG

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.

Ansible_CF3.JPG

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.

Ansible_CF1.JPG

cloudformation variables:

Ansible_CF4.JPG

 

 

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s