--- - name: Configure vlans switch_config: username: "{{ switch_vars.username }}" password: "{{ switch_vars.password }}" port: "{{ switch_vars.port }}" host: "{{ switch_vars.host }}" use_proxy: "{{ switch.use_proxy }}" version: v7 config: path: vlans create_method: POST subpath: - path: "{{ item.id }}" data: name: "{{ item.name }}" vlan_id: "{{ item.id }}" status: VS_PORT_BASED type: VT_STATIC loop: "{{ switch_vars.vlans }}" - name: Remove vlans switch_config: username: "{{ switch_vars.username }}" password: "{{ switch_vars.password }}" port: "{{ switch_vars.port }}" host: "{{ switch_vars.host }}" use_proxy: "{{ switch.use_proxy }}" version: v7 config: path: vlans subpath: - path: "{{ item }}" delete: true loop: "{{ switch_vars.delete_vlans }}" - name: Configure IP switch_config: username: "{{ switch_vars.username }}" password: "{{ switch_vars.password }}" port: "{{ switch_vars.port }}" host: "{{ switch_vars.host }}" use_proxy: "{{ switch.use_proxy }}" version: v7 config: path: "vlans/{{ item.0.id }}/ipaddresses" create_method: POST subpath: - path: "{{ item.1.mode }}-{{ item.1.ip }}" delete: "{{ item.1.delete | default(False) }}" data: ip_address_mode: "{{ item.1.mode }}" vlan_id: "{{ item.0.id }}" ip_address: version: "{{ item.1.version | default('IAV_IP_V4') }}" octets: "{{ item.1.ip }}" ip_mask: version: "{{ item.1.version | default('IAV_IP_V4') }}" octets: "{{ item.1.mask | default('255.255.255.0') }}" loop: "{{ switch_vars.vlans | subelements('ipaddresses', skip_missing=True) | selectattr('1.mode', '==', 'IAAM_STATIC') }}" - name: Configure vlan without IP switch_config: username: "{{ switch_vars.username }}" password: "{{ switch_vars.password }}" port: "{{ switch_vars.port }}" host: "{{ switch_vars.host }}" use_proxy: "{{ switch.use_proxy }}" version: v7 config: path: "vlans/{{ item.0.id }}/ipaddresses" create_method: POST subpath: - path: "{{ item.1.mode }}-0.0.0.0" delete: "{{ item.1.delete | default(False) }}" data: ip_address_mode: "{{ item.1.mode }}" vlan_id: "{{ item.0.id }}" loop: "{{ switch_vars.vlans | subelements('ipaddresses', skip_missing=True) | rejectattr('1.mode', '==', 'IAAM_STATIC') }}" ...