ec2 inventory script broke with 'module' object has no attribute 'boto3_inventory_conn'

Hello,

I am running Ubuntu 16.04 w/Ansible 2.0.0.2-2ubuntu1.

/etc/ansible$ wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py
/etc/ansible$ wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini
/etc/ansible$ chmod +x /etc/ansible/ec2.py

I have a credentials file in ~/.aws/credentials

/etc/ansible$ ./ec2.py --list
Traceback (most recent call last):
File “./ec2.py”, line 1600, in
Ec2Inventory()
File “./ec2.py”, line 193, in init
self.do_api_calls_update_cache()
File “./ec2.py”, line 527, in do_api_calls_update_cache
self.get_rds_instances_by_region(region)
File “./ec2.py”, line 633, in get_rds_instances_by_region
client = ec2_utils.boto3_inventory_conn(‘client’, ‘rds’, region, **self.credentials)
AttributeError: ‘module’ object has no attribute ‘boto3_inventory_conn’

I have installed boto and boto3 via both apt-get and pip with the same result.
I have found a few other versions of ec2.py but none of them work.

Any ideas?
Thanks!
Michael

The ec2.py inventory is not fully self contained and relies on functionality within ansible itself.

The file you pulled from github requires ansible 2.3 to function.

I installed the latest Ansible (2.3.1.0) from source and now I get:

/etc/ansible$ ./ec2.py --list --refresh-cache

{“msg”: “Error: Module unable to decode valid JSON on stdin. Unable to figure out what parameters were passed”, “failed”: true}

“./ec2.py --list” is now working. The correct ec2.py was from ansible-2.3.1.0/contrib/inventory/

Thanks for your help Matt. :slight_smile:

Michael

/etc/ansible/ec2.py --list works, but if I try to run from ansible I get this:

~/ansible/playbooks$ ansible -i /etc/ansible/ec2.py -u ubuntu us-east-1d -m ping
Traceback (most recent call last):
File “/usr/local/bin/ansible”, line 4, in
import(‘pkg_resources’).run_script(‘ansible==2.3.1.0’, ‘ansible’)
File “/usr/lib/python2.7/dist-packages/pkg_resources/init.py”, line 2927, in
@_call_aside
File “/usr/lib/python2.7/dist-packages/pkg_resources/init.py”, line 2913, in _call_aside
f(*args, **kwargs)
File “/usr/lib/python2.7/dist-packages/pkg_resources/init.py”, line 2940, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File “/usr/lib/python2.7/dist-packages/pkg_resources/init.py”, line 635, in _build_master
ws.require(requires)
File “/usr/lib/python2.7/dist-packages/pkg_resources/init.py”, line 943, in require
needed = self.resolve(parse_requirements(requirements))
File “/usr/lib/python2.7/dist-packages/pkg_resources/init.py”, line 829, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The ‘pycrypto>=2.6’ distribution was not found and is required by ansible

I installed the python-pycryptopp packge but that didn’t help.

It seems working fine with ansible 2.4.0