when item not in key of hash

55 views
Skip to first unread message

Rishi

unread,
May 7, 2015, 7:42:49 AM5/7/15
to ansible...@googlegroups.com
Trying to figure out if the following is possible.

I have a hash map e.g.

tools:
  a:
    foobar: 1
  b:
    barfoo: 3

- file: path=/some/dir/{{ item }} state=absent
  with_items: contents.stdout_lines
  when: item not in [[ list of tools keys ]]

I want  [[ list of tools keys ]] to turn into [a,b] basically so the when clause could work. Any way to do this?


Matt Martz

unread,
May 7, 2015, 8:07:20 AM5/7/15
to ansible...@googlegroups.com
tools.keys() would give you all of the keys.  However in Python/jinja2 this can be shortcut by just specifying tools such as:

when: item not in tools
--
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/d578b3b2-433d-400e-9dfc-c5400c310e0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Rishi Dhupar

unread,
May 7, 2015, 4:21:36 PM5/7/15
to ansible...@googlegroups.com
Wow simple, thanks!


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/ODP8Olev7Os/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages