So I wrote my own filter for this...
def idfromlistofdicts(l):
result = []
for item in l:
result.append(item['id'])
return result
class FilterModule(object):
def filters(self):
return {
'idfromlistofdicts': idfromlistofdicts,
}
Not sure if something like this already exists though.
On Monday, 14 September 2015 11:19:48 UTC+10, Rob White wrote:
>
> Hi all,
>
> I am using the ec2_vpc_subnet_facts module to get back a list of subnet
> dicts. I want to get the id from each of these dicts and add it to a new
> list so i end up with just a list of subnet ids. I thought this might be
> possible with existing jinja filters but i'm not sure where to start so any
> pointers would be appreciated.
>
> Example:
>
> 'subnets': [{u'availability_zone': u'ap-southeast-2a', u'tags': {u'Type':
> u'public', u'Zone': u'a', u'Env': u'support', u'Name':
> u'support-public-a'}, u'default_for_az': u'false', u'state': u'available',
> u'vpc_id': u'vpc-11223344', u'cidr_block': u'10.66.128.0/25',
> u'available_ip_address_count': 113, u'id': u'subnet-11223344',
> u'map_public_ip_on_launch': u'false'}, {u'availability_zone':
> u'ap-southeast-2b', u'tags': {u'Type': u'public', u'Zone': u'b', u'Env':
> u'support', u'Name': u'support-public-b'}, u'default_for_az': u'false',
> u'state': u'available', u'vpc_id': u'vpc-11223344', u'cidr_block': u'
> 10.66.129.0/25', u'available_ip_address_count': 118, u'id':
> u'subnet-55667788', u'map_public_ip_on_launch': u'false'}]
>
>
> I want to get each subnet.id in to a list so i end up with...
>
> my_list: [subnet-11223344, subnet-55667788]
>
> Thanks,
>
--
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/45836828-17fa-4274-b31d-8d5b59f3c510%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.