ansible-role-networking/tasks/main.yml

91 lines
2.6 KiB
YAML
Raw Normal View History

2022-03-18 13:27:26 +00:00
---
- name: Include OS-specific variables
2023-02-08 17:24:09 +00:00
ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"
2022-03-18 13:27:26 +00:00
2022-04-18 12:42:07 +00:00
- name: "Remove existing systemd-networkd configuration"
2023-02-08 17:24:09 +00:00
ansible.builtin.file:
2022-03-18 13:27:26 +00:00
path: "/etc/systemd/network"
state: absent
2022-04-18 12:42:07 +00:00
- name: "Create systemd-networkd directory"
2023-02-08 17:24:09 +00:00
ansible.builtin.file:
2022-03-18 13:27:26 +00:00
path: "/etc/systemd/network"
owner: root
group: root
mode: 0755
state: directory
- name: Create systemd.netdev files
block:
- name: Create systemd.netdev files
2023-02-08 17:24:09 +00:00
ansible.builtin.template:
2022-03-18 13:27:26 +00:00
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", "==", "Kind") and
2022-04-18 12:42:07 +00:00
item.netdev_options | selectattr("value", "!=", "wireguard")
2022-03-18 13:27:26 +00:00
with_items: "{{ systemd_networkd_netdev }}"
- name: Create sensitive systemd.netdev files
2023-02-08 17:24:09 +00:00
ansible.builtin.template:
2022-03-18 13:27:26 +00:00
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") and
2022-04-18 12:42:07 +00:00
item.netdev_options | selectattr("value", "equalto", "wireguard")
2022-03-18 13:27:26 +00:00
with_items: "{{ systemd_networkd_netdev }}"
2022-04-18 12:42:07 +00:00
no_log: true
2022-03-18 13:27:26 +00:00
notify: restart networkd
- name: Create systemd.networkd files
2023-02-11 15:01:34 +00:00
ansible.builtin.template:
2022-03-18 13:27:26 +00:00
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
2023-02-08 17:24:09 +00:00
ansible.builtin.file:
2022-03-18 13:27:26 +00:00
src: /run/systemd/resolve/stub-resolv.conf
dest: /etc/resolv.conf
state: link
2023-02-08 17:24:09 +00:00
force: true
follow: false
2022-03-18 13:27:26 +00:00
owner: root
group: root
2022-04-18 12:42:07 +00:00
- name: Start and enable systemd-networkd
2023-02-08 17:24:09 +00:00
ansible.builtin.systemd:
2022-03-18 13:27:26 +00:00
name: systemd-networkd
state: started
2023-02-08 17:24:09 +00:00
enabled: true
daemon_reload: true
2022-03-18 13:27:26 +00:00
2022-04-18 12:42:07 +00:00
- name: Start and enable systemd-resolved
2023-02-08 17:24:09 +00:00
ansible.builtin.systemd:
2022-03-18 13:27:26 +00:00
name: systemd-resolved
state: started
2023-02-08 17:24:09 +00:00
enabled: true
daemon_reload: true
2022-03-18 13:27:26 +00:00
2022-04-18 12:42:07 +00:00
- name: Set system timezone
2023-02-08 17:24:09 +00:00
community.general.timezone:
2022-03-18 13:27:26 +00:00
name: "{{ systemd_timesyncd_timezone }}"
2022-04-18 12:42:07 +00:00
- name: Start and enable systemd-timesyncd
2023-02-08 17:24:09 +00:00
ansible.builtin.systemd:
2022-03-18 13:27:26 +00:00
name: systemd-timesyncd
state: started
2023-02-08 17:24:09 +00:00
enabled: true
daemon_reload: true