Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions roles/systemd_networkd/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ systemd_networkd_link: {}
systemd_networkd_netdev: {}
systemd_networkd_network: {}
systemd_networkd_apply_config: false
systemd_networkd_enable_resolved: true
systemd_networkd_symlink_resolv_conf: true

systemd_networkd_cleanup: false
systemd_networkd_cleanup_patterns: []
Expand Down
6 changes: 0 additions & 6 deletions roles/systemd_networkd/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,3 @@
name: systemd-networkd
state: restarted
when: systemd_networkd_apply_config | bool

- name: Restart systemd-resolved
become: true
ansible.builtin.service:
name: systemd-resolved
state: restarted
44 changes: 3 additions & 41 deletions roles/systemd_networkd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
- name: Import config tasks
ansible.builtin.import_tasks: config.yml

- name: Make sure systemd-resolved is installed
become: true
ansible.builtin.package:
name: systemd-resolved
state: present
when:
- ansible_facts.distribution | lower == 'debian'
- ansible_facts.distribution_major_version >= '12'
- name: Include systemd-resolved role
ansible.builtin.include_role:
name: stackhpc.linux.systemd_resolved

- name: Enable systemd-networkd
become: true
Expand All @@ -31,37 +26,4 @@
name: systemd-networkd
enabled: true

- name: Enable and configure systemd-resolved
become: true
when: systemd_networkd_enable_resolved is truthy
block:
- name: Create a resolved.conf.d directory if it does not exist
ansible.builtin.file:
path: /etc/systemd/resolved.conf.d/
state: directory
mode: '0755'

- name: Configure dns.conf
ansible.builtin.template:
src: "dns_config.j2"
dest: "/etc/systemd/resolved.conf.d/dns.conf"
mode: "0644"
notify:
- Restart systemd-resolved

- name: Start and enable systemd-resolved
ansible.builtin.service:
name: systemd-resolved
enabled: true
state: started

- name: Replace /etc/resolv.conf with a symlink to the systemd-resolved stub
become: true
ansible.builtin.file:
path: /etc/resolv.conf
src: /run/systemd/resolve/stub-resolv.conf
state: link
force: true
when: systemd_networkd_symlink_resolv_conf | bool

# vim: set ts=2 sw=2:
6 changes: 6 additions & 0 deletions roles/systemd_resolved/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

systemd_networkd_enable_resolved: true
Comment thread
g0rgamesh marked this conversation as resolved.
Outdated
systemd_networkd_symlink_resolv_conf: true

# vim: set ts=2 sw=2:
14 changes: 14 additions & 0 deletions roles/systemd_resolved/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# handlers for ansible-role-systemd-resolved

- name: Restart systemd-resolved
become: true
ansible.builtin.service:
name: systemd-resolved
state: restarted

- name: Restart NetworkManager
become: true
ansible.builtin.service:
name: NetworkManager
state: restarted
67 changes: 67 additions & 0 deletions roles/systemd_resolved/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---

- name: Make sure systemd-resolved is installed
become: true
ansible.builtin.package:
name: systemd-resolved
state: present
when:
- ansible_facts.distribution | lower == 'debian'
- ansible_facts.distribution_major_version >= '12'
- ansible_facts.os_family == "RedHat"
- ansible_facts.distribution_major_version | int >= 10

- name: Enable and configure systemd-resolved
become: true
when: systemd_networkd_enable_resolved is truthy
block:
- name: Create a NetworkManager/conf.d directory if it does not exist
ansible.builtin.file:
path: /etc/NetworkManager/conf.d/
state: directory
mode: '0755'
when:
- ansible_facts.os_family == "RedHat"
- ansible_facts.distribution_major_version | int >= 10

- name: Configure NetworkManager dns.conf to use systemd-resolved
ansible.builtin.template:
src: "nm_dns_config.j2"
dest: "/etc/NetworkManager/conf.d/dns.conf"
mode: "0644"
notify:
- Restart NetworkManager
when:
- ansible_facts.os_family == "RedHat"
- ansible_facts.distribution_major_version | int >= 10

- name: Create a resolved.conf.d directory if it does not exist
ansible.builtin.file:
path: /etc/systemd/resolved.conf.d/
state: directory
mode: '0755'

- name: Configure dns.conf
ansible.builtin.template:
src: "dns_config.j2"
dest: "/etc/systemd/resolved.conf.d/dns.conf"
mode: "0644"
notify:
- Restart systemd-resolved

- name: Start and enable systemd-resolved
ansible.builtin.service:
name: systemd-resolved
enabled: true
state: started

- name: Replace /etc/resolv.conf with a symlink to the systemd-resolved stub
become: true
ansible.builtin.file:
path: /etc/resolv.conf
src: /run/systemd/resolve/stub-resolv.conf
state: link
force: true
when: systemd_networkd_symlink_resolv_conf | bool

# vim: set ts=2 sw=2:
4 changes: 4 additions & 0 deletions roles/systemd_resolved/templates/nm_dns_config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# {{ ansible_managed }}

[main]
dns=systemd-resolved
Loading