# pass ec2 tag to a task conditional

**URL:** <https://forum.ansible.com/t/pass-ec2-tag-to-a-task-conditional/21134>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [April 11, 2016, 9:57pm UTC](https://forum.ansible.com/t/pass-ec2-tag-to-a-task-conditional/21134 "2016-04-11T21:57:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Stivers](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@Paul\_Stivers](https://forum.ansible.com/u/Paul_Stivers)\
**Post date:** [April 11, 2016, 9:57pm UTC](https://forum.ansible.com/t/pass-ec2-tag-to-a-task-conditional/21134/1 "2016-04-11T21:57:10Z")

</div>

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.

`

---

<div class="post-metadata">

**Author:** ![viper233](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/viper233/32/2060_2.png) [@viper233](https://forum.ansible.com/u/viper233)\
**Post date:** [April 12, 2016, 9:58pm UTC](https://forum.ansible.com/t/pass-ec2-tag-to-a-task-conditional/21134/2 "2016-04-12T21:58:34Z")

</div>

[http://docs.ansible.com/ansible/ec2\_tag\_module.html](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.

---

<div class="post-metadata">

**Author:** ![Paul\_Stivers](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@Paul\_Stivers](https://forum.ansible.com/u/Paul_Stivers)\
**Post date:** [April 21, 2016, 10:11pm UTC](https://forum.ansible.com/t/pass-ec2-tag-to-a-task-conditional/21134/3 "2016-04-21T22:11:54Z")

</div>

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](http://docs.ansible.com/ansible/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script)

This worked

when: ec2\_tag\_Application == ‘my\_app’
