Amazon machine images (AMIs) are templates AWS uses when creating EC2 cloud servers. They are based on snapshots of existing servers.
Whenever you create an EC2 server, you will need to rely on an existing AMI. To save time when spinning up new servers, we maintain a set of AMIs that come pre-packaged with some of the more time-consuming software to compile and install, such as Ruby, Java, VIPS and ImageMagic.
We have automated the process of creating the AMIs themselves, using the build_ami
ansible role.
Outline
build_ami
spins up a new ec2 image; installs software on it; takes a snapshot of the server and creates an ami for later use; and finally destroys the ec2 image.
Software installed
Aside from packages
and system_setup
, which are run on all new machines, the following three optional software installation roles are run:
Sample role | What it does | When it runs |
---|---|---|
| Compiles and installs Ruby | If you pass |
| Compiles and installs | If you pass |
| Compiles and installs | If you pass |
Important files
File | Contents | |
---|---|---|
build_ami.yml | Outline of the role | |
group_vars/ruby_ami | ami metadata (instance type, disk size, aws name and tags) | |
group_vars/ruby_image_ami | ami metadata | |
roles/dzi/vars/role_vars | Current vips version | |
roles/ruby/vars/role_vars | Current ruby version | |
roles/imagemagick/vars/role_vars | Current imagemagick version |
Example invocations
ansible-playook --ask-vault-pass build_ami.yml --extra-vars "build=ruby_ami"
ansible-playook --ask-vault-pass build_ami.yml --extra-vars "build=ruby_image_ami"
ansible-playook --ask-vault-pass build_ami.yml --extra-vars "build=image_ami"