Hello,

Try the following playbook:

---
- hosts: all
  gather_facts: no
  vars:
    subnets: [ { id: subnet-11223344 }, { id: subnet-55667788 } ]
    my_list: |
      {%- set o = [] %}
      {%- for i in subnets %}
      {%-   if o.append(i.id) %}
      {%-   endif %}
      {%- endfor %}
      {{ o }}
  tasks:
    - debug:
        var: my_list


Sample session:

$ ansible-playbook -i localhost, playbook.yml

PLAY [all] 
******************************************************************** 

TASK: [debug ] 
**************************************************************** 
ok: [localhost] => {
    "var": {
        "my_list": [
            "subnet-11223344", 
            "subnet-55667788"
        ]
    }
}

PLAY RECAP 
******************************************************************** 
localhost                  : ok=1    changed=0    unreachable=0    failed=0 
  


On Monday, September 14, 2015 at 10:19:48 AM UTC+9, 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,
>

Regards,
--  
YAEGASHI Takeshi <[email protected]>

-- 
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/24094d45-846f-46e9-b992-b1511da4dd1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to