diff --git a/roles/networkd/tasks/main.yml b/roles/networkd/tasks/main.yml index c00f238..7f494f1 100644 --- a/roles/networkd/tasks/main.yml +++ b/roles/networkd/tasks/main.yml @@ -26,8 +26,8 @@ become: true template: src: netdev.j2 - dest: "/etc/systemd/network/{{ item.key }}.netdev" - loop: "{{ networking | dict2items }}" + dest: "/etc/systemd/network/{{ item.0.key + '.' + item.1 }}.netdev" + loop: "{{ networking | dict2items | subelements('value.vlans', true) }}" - import_tasks: services.yml diff --git a/roles/networkd/tasks/packages.yml b/roles/networkd/tasks/packages.yml index b0b76a9..08bf747 100644 --- a/roles/networkd/tasks/packages.yml +++ b/roles/networkd/tasks/packages.yml @@ -1,8 +1,34 @@ --- -- name: Install systemd-networkd +- name: Install networkd on Fedora + when: ansible_distribution == "Fedora" become: true dnf: state: latest name: - systemd-resolved - systemd-networkd + +- name: Install networkd on CentOS 7 + when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7" + become: true + yum: + state: latest + name: + - systemd-resolved + - systemd-networkd + +- name: Install networkd on CentOS 8 + when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "8" + become: true + block: + - name: Install this super-legitimate and definitely vetted COPR repo + shell: + creates: /etc/yum.repos.d/_copr:copr.fedorainfracloud.org:fschwarz:systemd-networkd.repo + cmd: dnf copr enable fschwarz/systemd-networkd + warn: false + - name: Install networkd + dnf: + state: latest + name: + # This now comes from aforementioned very good COPR repo + - systemd-networkd diff --git a/roles/networkd/tasks/services.yml b/roles/networkd/tasks/services.yml index 3d721f5..4a03b3d 100644 --- a/roles/networkd/tasks/services.yml +++ b/roles/networkd/tasks/services.yml @@ -5,7 +5,6 @@ name: "{{ item }}" enabled: false loop: - - network - NetworkManager - NetworkManager-wait-online @@ -26,7 +25,6 @@ name: "{{ item }}" state: stopped loop: - - network - NetworkManager - NetworkManager-wait-online diff --git a/roles/networkd/templates/netdev.j2 b/roles/networkd/templates/netdev.j2 index 73e28af..3f364b4 100644 --- a/roles/networkd/templates/netdev.j2 +++ b/roles/networkd/templates/netdev.j2 @@ -1,11 +1,9 @@ # ANSIBLE MANAGED FILE - DO NOT EDIT [NetDev] -Name={{ item.key }} +Name={{ item.0.key }} Kind=vlan -{% if item.value['kind'] == 'vlan' %} [VLAN] -Id={{ item.value['vlan'] }} -{% endif %} +Id={{ item.1 }} # EOF