{% for vlan in pillar['network']['vlan'] -%} {% set ifname = 'vlan.' + vlan['id']|string %} create device {{ ifname }}: cmd.run: - name: nmcli connection add type vlan con-name {{ ifname }} ifname {{ ifname }} dev {{ pillar['network']['interface'] }} id {{ vlan['id'] }} - unless: nmcli device show {{ ifname }} set ip address on {{ ifname }}: cmd.run: - name: nmcli connection modify {{ ifname }} ipv4.addresses {{ vlan['address'] }}/24 - unless: bash -c "if [[ \"$(nmcli connection show Wired\ connection\ 1 | sed -n 's/^ipv4.addresses.\s*\(.*\)$/\1/p')\" == "{{ vlan['address'] }}/24" ]]; then exit 0; else exit 1;fi" set ip static on {{ ifname }}: cmd.run: - name: nmcli connection modify {{ ifname }} ipv4.method manual - unless: bash -c "if [[ \"$(nmcli connection show Wired\ connection\ 1 | sed -n 's/^ipv4.method.\s*\(.*\)$/\1/p')\" == "manual" ]]; then exit 0; else exit 1;fi" bring up {{ ifname }}: cmd.run: - name: nmcli connection up {{ ifname }} - onchanges: - cmd: create device {{ ifname }} - cmd: set ip address on {{ ifname }} - cmd: set ip static on {{ ifname }} {% endfor %}