--- - name: Include OS-specific variables ansible.builtin.include_vars: "{{ ansible_os_family }}.yml" - name: "Remove existing systemd-networkd configuration" ansible.builtin.file: path: "/etc/systemd/network" state: absent - name: "Create systemd-networkd directory" ansible.builtin.file: path: "/etc/systemd/network" owner: root group: root mode: 0755 state: directory - name: Create systemd.netdev files block: - name: Create systemd.netdev files ansible.builtin.template: src: systemd.netdev.j2 dest: "/etc/systemd/network/{{ item.filename }}" owner: "{{ systemd_networkd_unix_user }}" group: "{{ systemd_networkd_unix_user }}" mode: 0644 when: item.netdev_options is defined and item.netdev_options | selectattr("key", "==", "Kind") and item.netdev_options | selectattr("value", "!=", "wireguard") with_items: "{{ systemd_networkd_netdev }}" - name: Create sensitive systemd.netdev files ansible.builtin.template: src: systemd.netdev.j2 dest: "/etc/systemd/network/{{ item.filename }}" owner: "{{ systemd_networkd_unix_user }}" group: "{{ systemd_networkd_unix_user }}" mode: 0600 when: item.netdev_options is defined and item.netdev_options | selectattr("key", "equalto", "Kind") and item.netdev_options | selectattr("value", "equalto", "wireguard") with_items: "{{ systemd_networkd_netdev }}" no_log: true notify: restart networkd - name: Create systemd.networkd files ansible.builtin.template: src: systemd.network.j2 dest: "/etc/systemd/network/{{ item.filename }}" owner: "{{ systemd_networkd_unix_user }}" group: "{{ systemd_networkd_unix_user }}" mode: 0644 with_items: "{{ systemd_networkd_network }}" notify: restart networkd - name: Create symlink to use systemd-resolved's stub-listener ansible.builtin.file: src: /run/systemd/resolve/stub-resolv.conf dest: /etc/resolv.conf state: link force: true follow: false owner: root group: root - name: Start and enable systemd-networkd ansible.builtin.systemd: name: systemd-networkd state: started enabled: true daemon_reload: true - name: Start and enable systemd-resolved ansible.builtin.systemd: name: systemd-resolved state: started enabled: true daemon_reload: true - name: Set system timezone community.general.timezone: name: "{{ systemd_timesyncd_timezone }}" - name: Start and enable systemd-timesyncd ansible.builtin.systemd: name: systemd-timesyncd state: started enabled: true daemon_reload: true