Using when: x in y if y is a list of dicts

8 views
Skip to first unread message

Rob White

unread,
Aug 18, 2015, 5:43:49 AM8/18/15
to Ansible Project
Hi guys,

I wonder if anyone knows if it's possible do use the 'in' clause with a list of dicts.

I have a list that looks like this:

[{u'state': None, u'id': u'i-233b31yy'}, {u'state': None, u'id': u'i-2a2281xx'}]

I want to add_host if an id is not in the list, something like:

vars:
  mylist
:
   
- {u'state': None, u'id': u'i-233b31yy'}
   
- {u'state': None, u'id': u'i-2a2281xx'}
tasks
:
  local_action
:
   
module: add_host
    name
: "{{ ansible_ec2_local_ipv4 }}"
   
group: not_in_elb
 
when: ansible_ec2_instance_id not in mylist

The above fails because the list items are dicts.  How can I just look at the id value of each dict in the list?
Reply all
Reply to author
Forward
0 new messages