Files
ansible-role-networking/tasks/main.yml
Markus Pesch 9afbe53230
All checks were successful
Lint Markdown files / markdown-lint (push) Successful in 13s
Ansible Linter / ansible-lint (push) Successful in 52s
fix: adapt when condition
2025-08-10 20:12:50 +02:00

90 lines
2.6 KiB
YAML

---
- name: "Include OS-specific variables"
ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"
- name: "Remove existing systemd-networkd configuration"
ansible.builtin.file:
path: "/etc/systemd/network"
state: absent
- name: "Create systemd-networkd directory"
ansible.builtin.file:
path: "/etc/systemd/network"
owner: root
group: root
mode: "0755"
state: directory
- name: Create systemd.netdev files
block:
- name: Create systemd.netdev files
ansible.builtin.template:
src: systemd.netdev.j2
dest: "/etc/systemd/network/{{ item.filename }}"
owner: "{{ systemd_networkd_unix_user }}"
group: "{{ systemd_networkd_unix_user }}"
mode: "0644"
when:
item.netdev_options is defined and
(item.netdev_options | selectattr('key', 'equalto', 'Kind') | map(attribute='value') | first) != 'wireguard'
with_items: "{{ systemd_networkd_netdev }}"
- name: Create sensitive systemd.netdev files
ansible.builtin.template:
src: systemd.netdev.j2
dest: "/etc/systemd/network/{{ item.filename }}"
owner: "{{ systemd_networkd_unix_user }}"
group: "{{ systemd_networkd_unix_user }}"
mode: "0600"
when: item.netdev_options is defined and
(item.netdev_options | selectattr('key', 'equalto', 'Kind') | map(attribute='value') | first) == 'wireguard'
with_items: "{{ systemd_networkd_netdev }}"
no_log: true
notify: Restart networkd
- name: Create systemd.networkd files
ansible.builtin.template:
src: systemd.network.j2
dest: "/etc/systemd/network/{{ item.filename }}"
owner: "{{ systemd_networkd_unix_user }}"
group: "{{ systemd_networkd_unix_user }}"
mode: "0644"
with_items: "{{ systemd_networkd_network }}"
notify: Restart networkd
- name: Create symlink to use systemd-resolved's stub-listener
ansible.builtin.file:
src: /run/systemd/resolve/stub-resolv.conf
dest: /etc/resolv.conf
state: link
force: true
follow: false
owner: root
group: root
- name: Start and enable systemd-networkd
ansible.builtin.systemd:
name: systemd-networkd
state: started
enabled: true
daemon_reload: true
- name: Start and enable systemd-resolved
ansible.builtin.systemd:
name: systemd-resolved
state: started
enabled: true
daemon_reload: true
- name: Set system timezone
community.general.timezone:
name: "{{ systemd_timesyncd_timezone }}"
- name: Start and enable systemd-timesyncd
ansible.builtin.systemd:
name: systemd-timesyncd
state: started
enabled: true
daemon_reload: true