Fix networkd templating integration and access permissions
This commit is contained in:
parent
d24a9b2713
commit
f66a1fb8cc
@ -1,20 +1,21 @@
|
|||||||
---
|
---
|
||||||
- name: Install systemd-networkd on Rocky
|
- name: Configure network settings
|
||||||
become: true
|
become: true
|
||||||
|
block:
|
||||||
|
- name: Install systemd-networkd on Rocky
|
||||||
ansible.builtin.dnf:
|
ansible.builtin.dnf:
|
||||||
name: systemd-networkd
|
name: systemd-networkd
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Ensure network config directory exists
|
- name: Ensure network config directory exists
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /etc/systemd/network
|
path: /etc/systemd/network
|
||||||
state: directory
|
state: directory
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: 0644
|
mode: 0755
|
||||||
|
|
||||||
- name: Create network files
|
- name: Create network files
|
||||||
become: true
|
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: network.j2
|
src: network.j2
|
||||||
dest: /etc/systemd/network/{{ item.key }}.network
|
dest: /etc/systemd/network/{{ item.key }}.network
|
||||||
@ -22,10 +23,11 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: "{{ ansible_user }}"
|
group: "{{ ansible_user }}"
|
||||||
loop: "{{ skylab_networking.interfaces | dict2items }}"
|
loop: "{{ skylab_networking.interfaces | dict2items }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.key }}"
|
||||||
|
|
||||||
- name: Create netdev files
|
- name: Create netdev files
|
||||||
become: true
|
when: item.value.type is defined
|
||||||
when: item.kind is defined
|
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: netdev.j2
|
src: netdev.j2
|
||||||
dest: /etc/systemd/network/{{ item.key }}.netdev
|
dest: /etc/systemd/network/{{ item.key }}.netdev
|
||||||
@ -33,31 +35,31 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: "{{ ansible_user }}"
|
group: "{{ ansible_user }}"
|
||||||
loop: "{{ skylab_networking.interfaces | dict2items }}"
|
loop: "{{ skylab_networking.interfaces | dict2items }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.key }}"
|
||||||
|
|
||||||
- name: Fetch existing network config directory contents
|
- name: Fetch existing network config directory contents
|
||||||
become: true
|
|
||||||
changed_when: false
|
changed_when: false
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: /usr/bin/ls /etc/systemd/network
|
cmd: /usr/bin/ls /etc/systemd/network
|
||||||
register: _network_config_dir_raw
|
register: _network_config_dir_raw
|
||||||
|
|
||||||
- name: Remove legacy network config files
|
- name: Remove legacy network config files
|
||||||
become: true
|
|
||||||
when: item.strip().replace('.netdev', '').replace('.network', '') not in skylab_networking.interfaces
|
when: item.strip().replace('.netdev', '').replace('.network', '') not in skylab_networking.interfaces
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /etc/systemd/network/{{ item }}
|
path: /etc/systemd/network/{{ item }}
|
||||||
state: absent
|
state: absent
|
||||||
loop: "{{ _network_config_dir_raw.stdout.split(' ') }}"
|
loop: "{{ _network_config_dir_raw.stdout_lines }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.strip() }}"
|
||||||
|
|
||||||
- name: Configure fallback DNS
|
- name: Configure fallback DNS
|
||||||
become: true
|
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/systemd/resolved.conf
|
path: /etc/systemd/resolved.conf
|
||||||
create: false
|
create: false
|
||||||
line: FallbackDNS=
|
line: FallbackDNS=
|
||||||
|
|
||||||
- name: Enable systemd-networkd
|
- name: Enable systemd-networkd
|
||||||
become: true
|
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
enabled: true
|
enabled: true
|
||||||
@ -66,8 +68,7 @@
|
|||||||
- systemd-networkd-wait-online
|
- systemd-networkd-wait-online
|
||||||
- systemd-resolved
|
- systemd-resolved
|
||||||
|
|
||||||
- name: Disable NetworkManager
|
- name: Disable NetworkManager
|
||||||
become: true
|
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
enabled: false
|
enabled: false
|
||||||
@ -75,14 +76,12 @@
|
|||||||
- NetworkManager
|
- NetworkManager
|
||||||
- NetworkManager-wait-online
|
- NetworkManager-wait-online
|
||||||
|
|
||||||
- name: Start systemd-resolved to enable symlink creation
|
- name: Start systemd-resolved to enable symlink creation
|
||||||
become: true
|
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: systemd-resolved
|
name: systemd-resolved
|
||||||
state: started
|
state: started
|
||||||
|
|
||||||
- name: Link system resolv.conf to systemd-resolved
|
- name: Link system resolv.conf to systemd-resolved
|
||||||
become: true
|
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
dest: /etc/resolv.conf
|
dest: /etc/resolv.conf
|
||||||
src: /run/systemd/resolve/resolv.conf
|
src: /run/systemd/resolve/resolv.conf
|
||||||
@ -90,8 +89,7 @@
|
|||||||
force: true
|
force: true
|
||||||
setype: net_conf_t
|
setype: net_conf_t
|
||||||
|
|
||||||
- name: Link systemd-resolved to multi-user target
|
- name: Link systemd-resolved to multi-user target
|
||||||
become: true
|
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
dest: /etc/systemd/system/multi-user.target.wants/systemd-resolved.service
|
dest: /etc/systemd/system/multi-user.target.wants/systemd-resolved.service
|
||||||
src: /usr/lib/systemd/system/systemd-resolved.service
|
src: /usr/lib/systemd/system/systemd-resolved.service
|
||||||
|
@ -14,17 +14,15 @@ DNS={{ server }}
|
|||||||
{% if item.value.bond is defined %}
|
{% if item.value.bond is defined %}
|
||||||
Bond={{ item.value.bond }}
|
Bond={{ item.value.bond }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if item.value.dhcp | default(false) %}
|
{% if item.value.dhcp | default(false) %}
|
||||||
|
|
||||||
Gateway={{ item.value.gateway | ansible.netcommon.ipaddr('address') }}
|
Gateway={{ item.value.gateway | ansible.netcommon.ipaddr('address') }}
|
||||||
{% for address in item.value.addresses %}
|
{% for address in item.value.addresses %}
|
||||||
Address={{ address | ansible.netcommon.ipaddr('host/prefix') }}
|
Address={{ address | ansible.netcommon.ipaddr('host/prefix') }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% for interface in skylab_networking.interfaces.keys() %}
|
{% for interface in skylab_networking.interfaces.keys() %}
|
||||||
{% if interface.startswith(item.key) and interface.partition('.')[2] | number %}
|
{% if interface.startswith(item.key) and interface.partition('.')[2] | regex_search('^[0-9]{1,4}$') and interface != item.key %}
|
||||||
VLAN={{ interface }}
|
VLAN={{ interface }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Reference in New Issue
Block a user