- tags: - lxc-host - lxc-host-network become: yes vars: file_prefix: "/etc/systemd/network/{{ lxc_host__networkd_number }}-lxc-host" br_if: "{{ lxc_host__br_if }}" internal_if: "{{ host_database[ansible_hostname].interfaces[lxc_host__internal_if] }}" block: - debug: var=br_if - debug: var=internal_if - name: Configure sysctl, enable ipv4 and ipv6 forwarding sysctl: name: "{{ item }}" value: 1 with_items: - net.ipv4.ip_forward - net.ipv6.conf.all.forwarding - name: enable systemd-networkd service: name: systemd-networkd enabled: yes state: started # - name: "/etc/systemd/network/50-0-lxc-host-{{ lxc_host__hardware_if }}.network" # notify: systemctl restart systemd-networkd # copy: # dest: "/etc/systemd/network/50-0-lxc-host-{{ lxc_host__hardware_if }}.network" # content: | # [Match] # Name={{ lxc_host__hardware_if }} # # [Network] # Address={{ hardware_if.ipv4.address }}/{{ hardware_if.ipv4.netmask }} # Gateway={{ hardware_if.ipv4.gateway }} - name: "{{ file_prefix }}-1-{{ lxc_host__internal_if }}.netdev" notify: systemctl restart systemd-networkd copy: dest: "{{ file_prefix }}-1-{{ lxc_host__internal_if }}.netdev" content: | [NetDev] Name={{ lxc_host__internal_if }} Kind=dummy - name: "{{ file_prefix }}-2-{{ lxc_host__internal_if }}.network" notify: systemctl restart systemd-networkd copy: dest: "{{ file_prefix }}-2-{{ lxc_host__internal_if }}.network" content: | [Match] Name={{ lxc_host__internal_if }} [Network] Bridge={{ br_if }} - name: "{{ file_prefix }}-3-{{ br_if }}.netdev" notify: systemctl restart systemd-networkd copy: dest: "{{ file_prefix }}-3-{{ br_if }}.netdev" content: | [NetDev] Name={{ br_if }} Kind=bridge - name: "{{ file_prefix }}-4-{{ br_if }}.network" notify: systemctl restart systemd-networkd copy: dest: "{{ file_prefix }}-4-{{ br_if }}.network" content: | [Match] Name={{ br_if }} [Network] {% if internal_if.ipv4 is defined %} Address={{ internal_if.ipv4.address }}/{{ internal_if.ipv4.netmask }} {% endif %} {% if internal_if.ipv6 is defined %} Address={{ internal_if.ipv6.address }}/{{ internal_if.ipv6.netmask }} {% endif %}