I have problems to make it working the ec2.py script for dynamic inventory.
Installed ansible on CentOS 7:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum --enablerepo=epel install ansible
Configure a simple hosts file and ssl key access. Running ansible:
ansible all -m ping
Get the expected output. Ansible is working.
Installed aws-cli:
wget -q https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
unzip awscli-bundle.zip
./awscli-bundle/install -i /opt/aws -b /usr/bin/aws
Configure credentials file in ~/.aws. Running aws:
aws ec2 describe-instances
Get the expected output. Aws-cli is working.
Installed boto.
yum --enablerepo=epel install python2-boto
Downloaded ec2.py and ec2.ini from links as in the official documentation (http://docs.ansible.com/ansible/latest/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script). Running it I get the following error:
[root@vm09 ansible]# ./ec2.py --list
Traceback (most recent call last):
File "./ec2.py", line 1642, in <module>
Ec2Inventory()
File "./ec2.py", line 193, in __init__
self.do_api_calls_update_cache()
File "./ec2.py", line 525, in do_api_calls_update_cache
self.get_instances_by_region(region)
File "./ec2.py", line 615, in get_instances_by_region
self.add_instance(instance, region)
File "./ec2.py", line 934, in add_instance
if self.group_by_platform:
AttributeError: 'Ec2Inventory' object has no attribute 'group_by_platform'
Tried to install ansible from git and with pip, same as boto. Always get the same error.
What I am missing here?
OK, so if you look at the PR that introduced the group_by_platform
functionality:
https://github.com/ansible/ansible/pull/27848/files
You can see that the code goes through possible attributes for grouping options. These attributes are made available higher up in the script:
https://github.com/ansible/ansible/blob/devel/contrib/inventory/ec2.py#L435-L462
The group_by_platform
attribute is (was) missing from the list over which the setattr loop iterates. Add it, and it will work.
This is actually fixed now (two hours ago):
https://github.com/ansible/ansible/commit/223f94ec563eb0f5fb95465bf440ffddd7828f8b
Pull the latest from git and it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With