2021-11-06 04:33:41 +00:00
|
|
|
---
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Configure network settings
|
2021-11-06 04:33:41 +00:00
|
|
|
become: true
|
2021-11-06 05:19:37 +00:00
|
|
|
block:
|
|
|
|
- name: Install systemd-networkd on Rocky
|
|
|
|
ansible.builtin.dnf:
|
|
|
|
name: systemd-networkd
|
|
|
|
state: present
|
2021-11-06 04:33:41 +00:00
|
|
|
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Ensure network config directory exists
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /etc/systemd/network
|
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
2021-11-06 04:33:41 +00:00
|
|
|
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Create network files
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: network.j2
|
|
|
|
dest: /etc/systemd/network/{{ item.key }}.network
|
|
|
|
mode: 0644
|
|
|
|
owner: root
|
|
|
|
group: "{{ ansible_user }}"
|
2021-11-07 01:37:15 +00:00
|
|
|
loop: "{{ skylab_networking | dict2items }}"
|
2021-11-06 05:19:37 +00:00
|
|
|
loop_control:
|
|
|
|
label: "{{ item.key }}"
|
2021-11-06 04:33:41 +00:00
|
|
|
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Create netdev files
|
2021-11-07 01:37:15 +00:00
|
|
|
when: item.value.device is defined
|
2021-11-06 05:19:37 +00:00
|
|
|
ansible.builtin.template:
|
|
|
|
src: netdev.j2
|
|
|
|
dest: /etc/systemd/network/{{ item.key }}.netdev
|
|
|
|
mode: 0644
|
|
|
|
owner: root
|
|
|
|
group: "{{ ansible_user }}"
|
2021-11-07 01:37:15 +00:00
|
|
|
loop: "{{ skylab_networking | dict2items }}"
|
2021-11-06 05:19:37 +00:00
|
|
|
loop_control:
|
|
|
|
label: "{{ item.key }}"
|
2021-11-06 04:33:41 +00:00
|
|
|
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Fetch existing network config directory contents
|
|
|
|
changed_when: false
|
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: /usr/bin/ls /etc/systemd/network
|
|
|
|
register: _network_config_dir_raw
|
2021-11-06 04:33:41 +00:00
|
|
|
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Remove legacy network config files
|
2021-11-07 01:37:15 +00:00
|
|
|
when: item.strip().replace('.netdev', '').replace('.network', '') not in skylab_networking
|
2021-11-06 05:19:37 +00:00
|
|
|
ansible.builtin.file:
|
|
|
|
path: /etc/systemd/network/{{ item }}
|
|
|
|
state: absent
|
|
|
|
loop: "{{ _network_config_dir_raw.stdout_lines }}"
|
|
|
|
loop_control:
|
|
|
|
label: "{{ item.strip() }}"
|
2021-11-06 04:33:41 +00:00
|
|
|
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Configure fallback DNS
|
|
|
|
ansible.builtin.lineinfile:
|
|
|
|
path: /etc/systemd/resolved.conf
|
|
|
|
create: false
|
|
|
|
line: FallbackDNS=
|
2021-11-06 04:33:41 +00:00
|
|
|
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Enable systemd-networkd
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: "{{ item }}"
|
|
|
|
enabled: true
|
|
|
|
loop:
|
|
|
|
- systemd-networkd
|
|
|
|
- systemd-networkd-wait-online
|
|
|
|
- systemd-resolved
|
2021-11-06 04:33:41 +00:00
|
|
|
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Disable NetworkManager
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: "{{ item }}"
|
|
|
|
enabled: false
|
|
|
|
loop:
|
|
|
|
- NetworkManager
|
|
|
|
- NetworkManager-wait-online
|
2021-11-06 04:33:41 +00:00
|
|
|
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Start systemd-resolved to enable symlink creation
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: systemd-resolved
|
|
|
|
state: started
|
2021-11-06 04:33:41 +00:00
|
|
|
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Link system resolv.conf to systemd-resolved
|
|
|
|
ansible.builtin.file:
|
|
|
|
dest: /etc/resolv.conf
|
|
|
|
src: /run/systemd/resolve/resolv.conf
|
|
|
|
state: link
|
|
|
|
force: true
|
|
|
|
setype: net_conf_t
|
2021-11-06 04:33:41 +00:00
|
|
|
|
2021-11-06 05:19:37 +00:00
|
|
|
- name: Link systemd-resolved to multi-user target
|
|
|
|
ansible.builtin.file:
|
|
|
|
dest: /etc/systemd/system/multi-user.target.wants/systemd-resolved.service
|
|
|
|
src: /usr/lib/systemd/system/systemd-resolved.service
|
|
|
|
state: link
|
|
|
|
force: true
|