Refs #8025 Solution to approach resolv.conf only on case no dhcp-client is used

This commit is contained in:
Xavi Lleó 2024-10-07 09:43:51 +02:00
parent 757d3dfe29
commit d6c51141bf
2 changed files with 19 additions and 4 deletions

View File

@ -4,3 +4,5 @@
tags: sysctl
- import_tasks: apparmor.yml
tags: apparmor
- import_tasks: resolv.yml
tags: resolv

View File

@ -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