Add Ansible configuration, Ansible inventory, dynamic inventory script, and Ansible playbooks for a learning environment that shows how to manage AWS infrastructure using Ansible. Signed-off-by: Scott S. Lowe <scott.lowe@scottlowe.org> |
||
|---|---|---|
| .. | ||
| ansible.cfg | ||
| create.yml | ||
| delete.yml | ||
| ec2.ini | ||
| ec2.py | ||
| inventory | ||
| README.md | ||
Using Ansible to Orchestrate AWS
These files provide an example of how to use Ansible to orchestrate actions on Amazon Web Services (AWS). These files were tested using Ansible 2.1.1 on macOS 10.11.5.
Contents
-
ansible.cfg: This file tells Ansible where to find the default inventory file (the file
inventoryin the same directory). -
create.yml: This Ansible playbook creates infrastructure on AWS. Be sure to edit this file to specify the values listed in the
varssection at the top of the file. -
delete.yml: This Ansible playbook leverages the
ec2.pydynamic inventory script to tear down (delete) AWS infrastructure. Be sure to edit this file to specify the values in thevarssections (one at the top and one farther down). -
ec2.ini: This file is the configuration file for the dynamic inventory script. Edit the
regions=line in this file to specify the AWS regions where instances may be running. -
ec2.py: This is a dynamic inventory script to query AWS APIs and generate an inventory that Ansible can use. No edits are needed to this file.
-
inventory: This is a simple Ansible inventory file that points to the local host. It includes a definition of "ansible_python_interpreter" to help work around Python virtualenv issues.
-
README.md: The file you're currently reading.
Instructions
These instructions assume that you have an AWS account, that you know your AWS access key ID and secret access key, and that Ansible is installed and working on your system.
-
Place the files from the
ansible-awsdirectory of this GitHub repository into a directory on your local system. You can clone the entire "learning-tools" repository (usinggit clone) or just download the specific files from theansible-awsfolder. -
Edit
create.ymlanddelete.ymlto specify the values listed in thevarssection of each file. Note that there are twovarssections indelete.ymlbecause there are two plays in the playbook. -
To create AWS infrastructure using ansible, run
ansible-playbook create.yml. -
To delete the infrastructure created in step 3, run
ansible-playbook -i ./ec2.py delete.yml.
Enjoy!
License
This content is licensed under the MIT License.