Skip to content

Commit

Permalink
Merge pull request #548 from konstruktoid/dns
Browse files Browse the repository at this point in the history
add manage_resolved
  • Loading branch information
konstruktoid authored Feb 16, 2024
2 parents 46f1d2e + 188ee69 commit 20a985a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions defaults/main/dns.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
manage_resolved: true

dns:
- 1.1.1.2
- 9.9.9.9
Expand Down
1 change: 1 addition & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@
- DNSSEC={{ dnssec }}
- DNSOverTLS={{ dns_over_tls }}
when:
- manage_resolved
- ansible_virtualization_type not in ["container", "docker", "podman"]

- name: Verify systemd timesyncd.conf
Expand Down
1 change: 1 addition & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ansible.builtin.import_tasks:
file: resolvedconf.yml
when:
- manage_resolved
- ansible_virtualization_type not in ["container", "docker", "podman"]
tags:
- dns
Expand Down
29 changes: 17 additions & 12 deletions tasks/resolvedconf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@
mode: "0644"
owner: root
group: root
notify:
- Reload systemd
register: resolved_conf

- name: Add nameservers to resolv.conf
- name: Ensure configuration is active
become: true
ansible.builtin.lineinfile:
dest: /etc/resolv.conf
line: nameserver {{ item }}
mode: "0644"
owner: root
group: root
state: present
loop: "{{ dns_merged | unique }}"
when:
- ansible_os_family == "RedHat"
- ansible_virtualization_type not in ["container", "docker", "podman"]
- resolved_conf is changed
block:
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true

- name: Restart resolved service
ansible.builtin.service:
name: systemd-resolved
state: restarted
register: resolved_service
failed_when:
- resolved_service is not success
- not 'Could not find the requested service' in resolved_service.msg

0 comments on commit 20a985a

Please sign in to comment.