From 9c0bf190e2174b2d3006f2f4e418a399c4420003 Mon Sep 17 00:00:00 2001 From: Jeltz Date: Sun, 2 Jan 2022 16:30:59 +0100 Subject: [PATCH] Add systemd-networkd role --- roles/systemd_networkd/handlers/main.yml | 20 ++++++++++++++ roles/systemd_networkd/tasks/main.yml | 30 +++++++++++++++++++++ roles/systemd_networkd/templates/link.j2 | 7 +++++ roles/systemd_networkd/templates/network.j2 | 17 ++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 roles/systemd_networkd/handlers/main.yml create mode 100644 roles/systemd_networkd/tasks/main.yml create mode 100644 roles/systemd_networkd/templates/link.j2 create mode 100644 roles/systemd_networkd/templates/network.j2 diff --git a/roles/systemd_networkd/handlers/main.yml b/roles/systemd_networkd/handlers/main.yml new file mode 100644 index 0000000..3733060 --- /dev/null +++ b/roles/systemd_networkd/handlers/main.yml @@ -0,0 +1,20 @@ +--- +- name: Update initramfs + command: + cmd: update-initramfs -u + +- name: Restart systemd-networkd + systemd: + name: systemd-networkd.service + state: restarted + +- name: Reboot required + file: + path: /var/run/reboot-required + state: touch + modification_time: preserve + access_time: preserve + owner: root + group: root + mode: u=rw,g=r,o=r +... diff --git a/roles/systemd_networkd/tasks/main.yml b/roles/systemd_networkd/tasks/main.yml new file mode 100644 index 0000000..13327e2 --- /dev/null +++ b/roles/systemd_networkd/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: Configure interfaces links + template: + src: link.j2 + dest: "/etc/systemd/network/10-{{ item.key }}.link" + owner: root + group: systemd-network + mode: u=rw,g=r,o= + loop: "{{ networkd_interfaces | dict2items }}" + notify: + - Update initramfs + - Reboot required + +- name: Configure interfaces networks + template: + src: network.j2 + dest: "/etc/systemd/network/10-{{ item.key }}.network" + owner: root + group: systemd-network + mode: u=rw,g=r,o= + loop: "{{ networkd_interfaces | dict2items }}" + notify: + - Restart systemd-networkd + +- name: Enable and start systemd-networkd + systemd: + name: systemd-networkd.service + enabled: true + state: started +... diff --git a/roles/systemd_networkd/templates/link.j2 b/roles/systemd_networkd/templates/link.j2 new file mode 100644 index 0000000..1f0b48a --- /dev/null +++ b/roles/systemd_networkd/templates/link.j2 @@ -0,0 +1,7 @@ +{{ ansible_managed | comment }} + +[Match] +MACAddress={{ item.value.mac_addr }} + +[Link] +Name={{ item.key }} diff --git a/roles/systemd_networkd/templates/network.j2 b/roles/systemd_networkd/templates/network.j2 new file mode 100644 index 0000000..b0566a6 --- /dev/null +++ b/roles/systemd_networkd/templates/network.j2 @@ -0,0 +1,17 @@ +{{ ansible_managed | comment }} + +[Match] +Name={{ item.key }} + +{% if not (item.value.link_local | default(true)) %} +[Network] +LinkLocalAddressing=no +{% endif %} + +{% for addr in item.value.ip_addrs | default([]) %} +[Address] +Address={{ addr }} +{% endfor %} + +[FairQueueingControlledDelay] +Parent=root