This repository illustrates the proposed workflow described on this blogpost for baking AMIs, launching instances and using Ansible to abstract both configuration logic flows, so I highly recommend you read it first.
The following sequence diagram describes the workflow:
In this example, we want to spin up an instance with Prometheus using a separated data volume, which is useful for instance failures and service upgrades. The flow is something like this:
This demo has the following requirements:
- AWS API access tokens
- Packer >= 1.0.0
- Ansible >= 2.3.0.0
To generate an AMI to be used in this workflow you'll just need to run:
# Get the repo
git clone https://github.com/kintoandar/bakery.git
cd bakery
# Download ansible roles dependencies
ansible-galaxy install -r ./requirements.yml -p ./roles
# Use packer to build the AMI (using ansible)
export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXX
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXX
packer build ./packer.json
Now, to test the new AMI, just launch it with an extra EBS volume and use the provided cloud-init configuration example as the user-data. After the boot, you can check the cloud-init log in the instance:
less /var/log/cloud-init-output.log
Be sure that /root/bakery/cloud-init.json
was created with all the required overrides for Ansible, specially the cloud_init=true
.
Happy baking 🍰