diff --git a/roles/debian-host/tasks/main.yml b/roles/debian-host/tasks/main.yml index e4f179a..11d6c3f 100644 --- a/roles/debian-host/tasks/main.yml +++ b/roles/debian-host/tasks/main.yml @@ -4,3 +4,5 @@ tags: sysctl - import_tasks: apparmor.yml tags: apparmor +- import_tasks: resolv.yml + tags: resolv diff --git a/roles/debian-host/tasks/resolv.yml b/roles/debian-host/tasks/resolv.yml index 9aeb5a4..60455c0 100644 --- a/roles/debian-host/tasks/resolv.yml +++ b/roles/debian-host/tasks/resolv.yml @@ -1,9 +1,22 @@ -- name: Replace /etc/resolv.conf +- name: Check if DNS is already configured + stat: + path: /etc/resolv.conf + register: resolv_conf +- name: Read /etc/resolv.conf + slurp: + path: /etc/resolv.conf + register: resolv_conf_content + when: resolv_conf.stat.exists +- name: Check if DNS servers are already present + set_fact: + dns_configured: "{{ resolv_conf_content['content'] | b64decode | regex_search('^nameserver') is not none }}" + when: resolv_conf.stat.exists +- name: Apply resolv.conf template only if DNS is not configured template: - src: resolv.conf - dest: /etc/ + src: templates/resolv.conf + dest: /etc/resolv.conf owner: root group: root mode: '0644' backup: true - when: resolv_enabled + when: not resolv_conf.stat.exists or not dns_configured