Update Ansible support across several different areas Signed-off-by: Scott Lowe <scott.lowe@scottlowe.org> |
||
|---|---|---|
| .. | ||
| roles/docker-ce-edge/tasks | ||
| ansible.yml | ||
| README.md | ||
| template.json | ||
| variables.json | ||
Building an AWS AMI with Packer and Ansible
These files show an example of how to use Packer (https://www.packer.io/) along with Ansible (https://www.ansible.com/) to create a custom AMI on Amazon Web Services (AWS). This environment was tested using Packer 1.0.0 and Ansible 2.3.0.0 on Fedora 25, but it should work identically on any system where Packer and Ansible are supported.
Prerequisites
- These files do not supply any sort of AWS authentication credentials. If you have the AWS CLI installed and configured, then no additional action is needed. If you do not have the AWS CLI installed and configured, then you'll need to add your AWS authentication credentials to
template.json(details on what must be added are available here).
Contents
-
ansible.yml: This Ansible playbook applies the "docker-ce-edge" role to the AMI being created by Packer, and is called by
template.json. -
README.md: This file you're currently reading.
-
roles: This directory contains the "docker-ce-edge" Ansible role.
-
template.json: This is the Packer template that provides Packer with the information on how to build the custom AMI. Aside from adding AWS authentication credentials (as described in the "Prerequisites" section), no edits to this file should be needed.
-
variables.json: This JSON file supplies variables to be consumed by Packer. You will need to edit this file to supply a VPC ID and subnet ID. You may also want to edit the name and description variables to suit your needs.
Instructions
These instructions assume you've already installed Packer and Ansible. Refer to the documentation for these products for information on how to install them.
-
Place the files from the
packer/aws-ami-ansibledirectory of this GitHub repository into a directory on your local system. You can clone the entire "learning-tools" repository (usinggit clone), download a ZIP file of the entire "learning-tools" repository, or just download the specific files from the thepacker/aws-ami-ansiblefolder. -
If you are not using the AWS CLI on the system where you'll use this environment, you'll need to edit
template.jsonto supply AWS authentication credentials. (See the "Prerequisites" section above.) -
Edit
variables.jsonto supply a VPC ID and subnet ID where you'd like Packer to launch the temporary build instance. You may also want to customize the AWS region used and/or the name or description variables. -
From a terminal window in the directory where these files were placed, run
packer validate -var-file=variables.json template.jsonto validate that Packer has all the information it needs and that no syntax errors were introduced in previous steps. -
Run
packer build -var-file=variables.json template.jsonto run the build process. This will take a few minutes. When it's all said and done, Packer will output the AMI ID of the newly-created AMI. You can now use this AMI ID to launch instances, and these instances will be preconfigured with the Edge build of Docker CE.
Enjoy!