Skip to content

Instantly share code, notes, and snippets.

# Ansible EC2 external inventory script settings
#
[ec2]
# AWS regions to make calls to. Set this to 'all' to make request to all regions
# in AWS and merge the results together. Alternatively, set this to a comma
# separated list of regions. E.g. 'us-east-1,us-west-1,us-west-2'
regions = us-east-1
regions_exclude = us-gov-west-1,cn-north-1
#!/usr/bin/env python
'''
EC2 external inventory script
=================================
Generates inventory that Ansible can understand by making API request to
AWS EC2 using the Boto library.
NOTE: This script assumes Ansible is being executed where the environment
@all:
|--@ec2:
| |--54.173.53.76
| |--54.208.143.201
|--@ungrouped:
@all:
|--@aws_ec2:
| |--54.173.53.76
| |--54.208.143.201
|--@ungrouped:
# Example using filters
plugin: aws_ec2
# Populate inventory with instances in these regions
regions:
- us-east-1
filters:
# All dev and QA hosts
tag:Environment:
- dev
- qa
nginx_port: 80
---
- debug:
msg: "Nginx port number is: {{ nginx_port }}"
all:
vars:
nginx_port: 81
children:
server:
hosts: "127.0.0.1"
---
- hosts: server
gather_facts: no
connection: local
vars:
nginx_port: 82
roles:
- roles/nginx
---
all:
children:
dev-server:
hosts: <your remote server ip or hostname>
vars:
drupal_port: 80
nginx_port: 80
mysql_port: 3306
mysql_root_pass: !vault |