0
votes

I've setup Amazon's dynamic inventory for Ansible according to https://aws.amazon.com/blogs/apn/getting-started-with-ansible-and-dynamic-amazon-ec2-inventory-management/. I'm able to get an inventory of every EC2 instance on this account but I'd like to filter that down using tags. I've set instance_filters in my ec2.ini but the script still returns the entire inventory.

instance_filters = tag:environment=qa
ansible all -i ec2.py -m ping

I also made sure the environment variable to point to ec2.ini was set.

export EC2_INI_PATH=/path/to/ec2.ini/its/different/on/my/machine/I/swear

What steps/configs am I missing that actually filters EC2 instances?

1
Please show how EC2 instances are tagged just in case?mon
It would also be interesting to know what aws ec2 describe-instances --filter Name=tag,Values=environment=qa has to say, since it's possible you are expecting a shorter list than is really coming back. You can also just run that inventory manually to ensure you and it are on the same page EC2_INI_PATH=whatever python ./ec2.py --listmdaniel
Maybe you're using a different version of the aws utility but I had to use this syntax: aws ec2 describe-instances --filter Name=tag:environment,Values=qakfreezy

1 Answers

0
votes

The instance_filters config was working as expected. The problem was that the extra "hosts" I was picking up were actually ElasiCache clusters. In order to exclude those from inventory I had to add the config below to ec2.ini.

elasticache = False