pass ec2 tag to a task conditional

Is there a way to pass the value of an ec2 tag to a conditional in an ansible task? Boto is installed and used to determine which tagged ec2 servers the playbook is run against.

For example:

ec2 server with tag name “Application” and value “my_app”

ansible command to run a playbook

$ AWS_PROFILE=paul-dev ansible-playbook playbooks/paul_test.yml -i inventories/ec2.py -l 'tag_Environment_dev:&tag_Application_my_app' -e "app=my_app" -u ubuntu -s

works for the simple playbook containing this task because of the extra variable “app=my_app” on the commandline.

`

http://docs.ansible.com/ansible/ec2_tag_module.html

You will need to “list” the tags first of the instance to see what tags are set.

Something like

when: ec2_tags.tags.Application == ‘my_app’

should give you what you want.

Good clue, Steve. Thanks.

Got me thinking, I’m using the EC2 external inventory script, so from the variable list here http://docs.ansible.com/ansible/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script

This worked

when: ec2_tag_Application == ‘my_app’