This repository provides a starter template for getting started creating AWS infrastructure using Ansible and CloudFormation.
To run this playbook on your local machine, you must install the following prerequisites:
- Ansible 2.4 or higher
- Python PIP package manager
- The following PIP packages:
- awscli
- boto3
- netaddr
- jq
You must also configure your local environment with your AWS credentials and you will also need to specify the ARN of the IAM role that your playbook will use to run provisioning tasks. Your credentials must have permissions to assume this role.
On macOS environments it is recommended that you use the Homebrew package manager to install the most recent version of Python 2.7.
See brew.sh for details on how to install Homebrew.
Once Homebrew is installed you can install the latest version of Python 2.7 as follows:
$ brew install python@2
...
...
This will install the PIP package manager as pip2
and you can install Ansible and required dependencies:
$ pip2 install ansible awscli boto3 netaddr
...
...
Note that boto3
must also be installed in the system python, which you can perform as follows:
$ sudo -H /usr/bin/python -m easy_install pip
...
...
$ sudo -H /usr/bin/python -m pip install boto3 --ignore-installed six
...
...
Once you have installed boto3
in your system python, it is recommended to run the following commands to ensure your Homebrew and system python environments are configured correctly:
$ brew unlink python
...
$ brew link --overwrite python
...
- Fork this repository to your own new repository
- Review
roles/requirements.yml
and modify if required - Install roles by running
make roles
(which executesansible-galaxy install -r roles/requirements.yml
) - Define environments in the
inventory
file andgroup_vars
folder. Alternatively you can use themake environment/<environment-name>
command. - Define a CloudFormation stack name in
group_vars/all/vars.yml
using theStack.Name
variable - Add the ARN of the IAM role to assume in each environment by configuring the
Sts.Role
variable ingroup_vars/<environment>/vars.yml
- Define your CloudFormation template in
templates/stack.yml.j2
. Alternatively you can reference a template included with theaws-cloudformation
role by setting theStack.Template
variable to the path of the template relative to theaws-cloudformation
role folder (e.g.Stack.Template: templates/network.yml.j2
) - Define environment-specific configuration settings as required in
group_vars/<environment>/vars.yml
- If you have stack inputs, define them using the syntax
Stack.Inputs.<Parameter>
in your environment settings file (e.g.Stack.Inputs.MyInputParam: some-value
) - Deploy your stack by running
make deploy/<environment>
(which executesansible-playbook site.yml -e env=<environment>
)
-
Environment specific settings should always be formatted
Config.<Parameter>
(e.g.Config.VpcName
), unless you have environment specific settings for variables related to theaws-sts
oraws-cloudformation
roles as defined below -
Variables related to configuring the
aws-sts
role are formattedSts.<Parameter>
(e.g.Sts.Role
) -
Variables related to configuring the
aws-cloudformation
role formattedStack.<Parameter>
(e.g.Stack.Name
)