Selecting subelements from variable

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

can you please try "

vpc_subnets | map(attribute=‘cidr’)| list

Thanks Benno, that worked!

– Viktor