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.
---
- hosts: all
tasks:
- name: tree package is present
apt: name=tree state=present
when: app == 'my_app'
If I want to avoid including an extra variable on the command line, is there a way to access the ec2 tag name and value in a task conditional? The tag name and value are referenced in the command to run the playbook, "&tag_Application_my_app", but I haven't found a way to reference it in a task.
I get the following error when running the playbook with the following attempts at conditionals on the ec2 tag
---
- hosts: all
tasks:
- name: tree package is present
apt: name=tree state=present
when: tag_Application == 'my_app'
# when: Application = 'my_app'
# when: tag_Application_my_app
fatal: [10.5.81.130] => ERROR! error while evaluating conditional: tag_Application_cis_acord_1203
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2a6129a9-760b-4500-83d1-b187b2aa3ebb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
http://docs.ansible.com/ansible/ec2_tag_module.htmlYou 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.
--Steve