Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

While running  multiple inventory with ec2.py; You will also need to copy the ec2.ini file to location where you have ec2.py.

My structure was with 4 different environment and i didnt want to copy ec2.py all over the inventory rather use 1 and create ec2.ini according to requirement per environment. (which may be what many would like to do).

root@tikejhya:/etc/ansible# tree
.
├── development
│ └── ec2.ini
├── ec2.py
├── ext.py
├── ext.pyc
├── prod
│ └── ec2.ini
├── roles
├── staging
│ └── ec2.ini
└── uat
├── base
└── ec2.ini

Since there was not really out of the box solution; i created ext.py below and import into ec2.py.

#ec2.py

135 from ansible.module_utils import ec2 as ec2_utils
++ 136 from ext import mapper
137
138 HAS_BOTO3 = False

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

And:

487 help='Use boto profile for connections to EC2')
++ 488 parser.add_argument('--my_env', action='store', dest='my_env',
help='Use env for veriable')
490 self.args = parser.parse_args()
491
++ 492 mapper(self.args.my_env)

#ext.py
#!/usr/bin/python
import os
import sys

def mapper(self_args_my_env):
os.environ[“EC2_INI_PATH”] = “/etc/ansible/” + self_args_my_env + “/ec2.ini”
os.environ[“AWS_PROFILE”] = “profile_” + self_args_my_env

This made me able to run ansible with ec2.py followed by env parameter and use relevent boto profile.

ec2.py –my_env uat –list