From abb56c21a737f1781267c28a8aba118042b9c9e5 Mon Sep 17 00:00:00 2001 From: Matthew Mosesohn Date: Thu, 22 Sep 2016 17:38:01 +0300 Subject: [PATCH] Improve management of nameservers in resolv.conf Changing nameservers now will clean up previous entries --- roles/dnsmasq/tasks/main.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/roles/dnsmasq/tasks/main.yml b/roles/dnsmasq/tasks/main.yml index f98afd6bd..f633485d2 100644 --- a/roles/dnsmasq/tasks/main.yml +++ b/roles/dnsmasq/tasks/main.yml @@ -86,14 +86,17 @@ follow: yes - name: Add local dnsmasq to resolv.conf - lineinfile: - line: "nameserver {{item}}" + blockinfile: dest: "{{resolvconffile}}" + block: |- + {% for item in nameserverentries -%} + nameserver {{ item }} + {% endfor %} state: present - insertafter: "^search.*$" + create: yes backup: yes follow: yes - with_items: "{{nameserverentries}}" + marker: "# Ansible nameservers {mark}" - name: Add options to resolv.conf lineinfile: