Selecting subelements from variable

23 views
Skip to first unread message

Viktor Szathmáry

unread,
Jun 15, 2015, 8:38:47 AM6/15/15
to ansible...@googlegroups.com
Hi,

Let's say I have a variable structure like this:

vpc_subnets:
  - cidr: "172.22.1.0/24"
    az: "us-east-1a"
  - cidr: "172.22.2.0/24"
    az: "us-east-1b"
  - cidr: "172.22.3.0/24"
    az: "us-east-1c"

... and a task using it:

ec2_vpc:
  ...
  subnets: "{{ vpc_subnets }}"
  route_tables:
    - subnets:
        - "172.22.1.0/24"
        - "172.22.2.0/24"
        - "172.22.3.0/24"
      routes:
        - dest: 0.0.0.0/0
          gw: igw


I would like to avoid repeating the CIDRs in route_tables/subnets, and just select all the CIDRs from the vpc_subnets variable. Is there a nice way of doing this?

Thanks,
  Viktor

benno joy

unread,
Jun 15, 2015, 8:52:56 AM6/15/15
to ansible...@googlegroups.com
can you please try "

vpc_subnets | map(attribute='cidr')| list



--
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/b538a1bc-b45d-4535-947c-c3940a3d80dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Viktor Szathmáry

unread,
Jun 16, 2015, 6:13:15 AM6/16/15
to ansible...@googlegroups.com

Thanks Benno, that worked!

– Viktor
Reply all
Reply to author
Forward
0 new messages