I am trying to set multiple values for 2 variables that I am using in the following code:
- name: Create the subnets
os_subnet:
cloud: "{{ item.cloud }}"
state: present
validate_certs: no
no_gateway_ip: yes
enable_dhcp: yes
name: "{{ item.subnet }}"
network_name: "{{ item.network }}"
cidr: "{{ item.cidr }}"
allocation_pool_start: "{{ item.allocation_pool_start }}"
allocation_pool_end: "{{ item.allocation_pool_end }}"
host_routes:
- destination: "{{ item.destination | default(omit) }}"
nexthop: "{{ item.nexthop | default(omit) }}"
with_items:
- "{{ subnets }}"
tags: create_subnets
In my environment, some subnets have a different number of host_routes or none. My variable file with one variable for destination+nexthop looks now like:
--- #
subnets:
- { cloud: tenant1, network: nw, subnet: nw_subnet, cidr: 172.10.10.224/27, allocation_pool_start: 172.10.10.228, allocation_pool_end: 172.10.10.254, destination: 10.10.10.0/24, nexthop: 172.10.114.125 }
And this works. But if I am having more than one value for destination+nexthop, how shall I proceed? I have tried yet to duplicate the same line and change just in the end the destination+nexthop, but didn't worked. If I am trying add in the same list one the same row another destination+nexthop, it will take just the last value.
Define
host_routes
as list in the subnets variable:Now you can use it in your task