I am going nuts over what seems to be a very simple thing.
I am using ec2.py. I want a list of the EC2 instance IDs, but only of
instances that are tagged with a particular name and value, e.g.
MyTag:MyValue.
I know that {{ hostvars.XXX.groups.tag_MyTag_MyValue }} exists for any host
tagged with MyTag:MyValue.
I also know that {{hostvars.XXX.ec2_id}} will get me the ID of the instance
named XXX.
I can get a list of ALL the instance IDs like this:
- set_fact:
ids: []
- set_fact:
ids: "{{ ids }} + [ '{{ hostvars[item].ec2_id }}' ]"
with_items: "{{ hostvars |list }}"
I feel I should be able to add a when: clause after the with_items: clause,
something like:
when: item in hostvars.item.groups.tag_MyTag_MyValue
... but that causes an error saying that hostvars has no attribute called
"item". If I try to dereference it ("{{ item }}") Jinja tells me I can't
use curly braces in when: statements.
Any clues?
Regards, K.
PS: ec2.py directly returns what I am after - it returns the tag groups
outside the hostvars. Is there some way I can access that from inside
Ansible? Those groups seem only to be accessible via the hosts: directive,
which is no use to me as I need this list inside a role.
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/31bec1cc-1bb8-4acd-a12e-248c4b50bef2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.