100 lines
2.5 KiB
YAML
100 lines
2.5 KiB
YAML
|
---
|
||
|
- name: Install systemd-networkd on Rocky
|
||
|
become: true
|
||
|
ansible.builtin.dnf:
|
||
|
name: systemd-networkd
|
||
|
state: present
|
||
|
|
||
|
- name: Ensure network config directory exists
|
||
|
ansible.builtin.file:
|
||
|
path: /etc/systemd/network
|
||
|
state: directory
|
||
|
owner: root
|
||
|
group: root
|
||
|
mode: 0644
|
||
|
|
||
|
- name: Create network files
|
||
|
become: true
|
||
|
ansible.builtin.template:
|
||
|
src: network.j2
|
||
|
dest: /etc/systemd/network/{{ item.key }}.network
|
||
|
mode: 0644
|
||
|
owner: root
|
||
|
group: "{{ ansible_user }}"
|
||
|
loop: "{{ skylab_networking.interfaces | dict2items }}"
|
||
|
|
||
|
- name: Create netdev files
|
||
|
become: true
|
||
|
when: item.kind is defined
|
||
|
ansible.builtin.template:
|
||
|
src: netdev.j2
|
||
|
dest: /etc/systemd/network/{{ item.key }}.netdev
|
||
|
mode: 0644
|
||
|
owner: root
|
||
|
group: "{{ ansible_user }}"
|
||
|
loop: "{{ skylab_networking.interfaces | dict2items }}"
|
||
|
|
||
|
- name: Fetch existing network config directory contents
|
||
|
become: true
|
||
|
changed_when: false
|
||
|
ansible.builtin.command:
|
||
|
cmd: /usr/bin/ls /etc/systemd/network
|
||
|
register: _network_config_dir_raw
|
||
|
|
||
|
- name: Remove legacy network config files
|
||
|
become: true
|
||
|
when: item.strip().replace('.netdev', '').replace('.network', '') not in skylab_networking.interfaces
|
||
|
ansible.builtin.file:
|
||
|
path: /etc/systemd/network/{{ item }}
|
||
|
state: absent
|
||
|
loop: "{{ _network_config_dir_raw.stdout.split(' ') }}"
|
||
|
|
||
|
- name: Configure fallback DNS
|
||
|
become: true
|
||
|
ansible.builtin.lineinfile:
|
||
|
path: /etc/systemd/resolved.conf
|
||
|
create: false
|
||
|
line: FallbackDNS=
|
||
|
|
||
|
- name: Enable systemd-networkd
|
||
|
become: true
|
||
|
ansible.builtin.systemd:
|
||
|
name: "{{ item }}"
|
||
|
enabled: true
|
||
|
loop:
|
||
|
- systemd-networkd
|
||
|
- systemd-networkd-wait-online
|
||
|
- systemd-resolved
|
||
|
|
||
|
- name: Disable NetworkManager
|
||
|
become: true
|
||
|
ansible.builtin.systemd:
|
||
|
name: "{{ item }}"
|
||
|
enabled: false
|
||
|
loop:
|
||
|
- NetworkManager
|
||
|
- NetworkManager-wait-online
|
||
|
|
||
|
- name: Start systemd-resolved to enable symlink creation
|
||
|
become: true
|
||
|
ansible.builtin.systemd:
|
||
|
name: systemd-resolved
|
||
|
state: started
|
||
|
|
||
|
- name: Link system resolv.conf to systemd-resolved
|
||
|
become: true
|
||
|
ansible.builtin.file:
|
||
|
dest: /etc/resolv.conf
|
||
|
src: /run/systemd/resolve/resolv.conf
|
||
|
state: link
|
||
|
force: true
|
||
|
setype: net_conf_t
|
||
|
|
||
|
- name: Link systemd-resolved to multi-user target
|
||
|
become: true
|
||
|
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
|