Finding key in list of dicts in when

37 views
Skip to first unread message

Paul Tötterman

unread,
May 26, 2016, 9:03:42 AM5/26/16
to Ansible Project
Hi,

Related to the recent mount deprecation thread:

- command: mount /srv
  when: "'/srv' not in [x['mount'] for x in ansible_mounts]"

But it seems that when statement is too complex. Any ideas how to express that in a valid way?

Ideas about how to use mount: state=mounted without touching fstab also welcome

Cheers,
Paul

Paul Tötterman

unread,
May 30, 2016, 3:19:23 AM5/30/16
to Ansible Project
But it seems that when statement is too complex. Any ideas how to express that in a valid way?

I ended up writing a filter that lets me do: when: not ansible_mounts|is_mounted('/srv')

Cheers,
Paul 

Daniel Nägele

unread,
May 30, 2016, 3:46:19 AM5/30/16
to ansible...@googlegroups.com
I've had some success using the following expression (to check wether
ansible is in a list of installed packages or if it is from pip/manual
install):

"{{ 'ansible' in pkgs.results|default([])|map(attribute='name') }}"

Regards,
Daniel
> --
> 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
> <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com
> <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/872c67cf-9a08-47ba-b0a4-3b479f6cd213%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/872c67cf-9a08-47ba-b0a4-3b479f6cd213%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Paul Tötterman

unread,
May 31, 2016, 3:49:52 AM5/31/16
to Ansible Project, ansible...@danieln.de
"{{ 'ansible' in pkgs.results|default([])|map(attribute='name') }}"

Thank you Daniel, that avoids the heavy-handed approach of a filter plugin.

Cheers,
Paul 
Reply all
Reply to author
Forward
0 new messages