From d6c51141bf81e2faa8d7b0798d48e41b64d0dc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavi=20Lle=C3=B3=20Tom=C3=A1s?= Date: Mon, 7 Oct 2024 09:43:51 +0200 Subject: [PATCH] Refs #8025 Solution to approach resolv.conf only on case no dhcp-client is used --- roles/debian-host/tasks/main.yml | 2 ++ roles/debian-host/tasks/resolv.yml | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) 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