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.