]> git.phdru.name Git - ansible.git/blobdiff - playbooks/debian/roles/named/tasks/main.yml
Feat(named): Setup `/etc/resolv.conf` to use installed BIND
[ansible.git] / playbooks / debian / roles / named / tasks / main.yml
index 7e433ec9fe3e7615e336cd63a5ffae5e9654151a..d3bf3da20a2c3058d87e6e188a3b1e6fb938c6ab 100644 (file)
@@ -1,38 +1,46 @@
 - name: Check named.conf.options
   become: true
-  shell: "grep -c '^\\s*allow-query' /etc/bind/named.conf.options || echo 0"
+  shell: "grep -c '^\\s*allow-query' /etc/bind/named.conf.options || :"
   register: named_conf
-  changed_when: named_conf.stdout == "0"
+  changed_when: named_conf.stdout in ('', "0")
 
 - debug:
     msg: "BIND has already been configured"
-  when: named_conf.stdout != "0"
+  when: named_conf.stdout not in ('', "0")
 
-- name: Install BIND
-  become: true
-  apt:
-    autoclean: yes
-    autoremove: yes
-    install_recommends: no
-    name: bind9
-    purge: yes
-    state: latest
-    update_cache: yes
-  when: named_conf.stdout == "0"
+- block:
+    - name: Install BIND
+      become: true
+      apt:
+        autoclean: yes
+        autoremove: yes
+        install_recommends: no
+        name: bind9
+        purge: yes
+        state: latest
+        update_cache: yes
 
-- name: Configure BIND
-  become: true
-  copy:
-    src: named.conf.options
-    dest: /etc/bind/named.conf.options
-    owner: bind
-    group: bind
-    mode: '0600'
-  when: named_conf.stdout == "0"
+    - name: Configure BIND
+      become: true
+      copy:
+        src: named.conf.options
+        dest: /etc/bind/named.conf.options
+        owner: bind
+        group: bind
+        mode: '0600'
 
-- name: Reload BIND
-  become: true
-  service:
-    name: bind9
-    state: reloaded
-  when: named_conf.stdout == "0"
+    - name: Reload BIND
+      become: true
+      service:
+        name: bind9
+        state: reloaded
+
+    - name: Configure resolver
+      become: true
+      copy:
+        content: "nameserver 127.0.0.1"
+        dest: /etc/resolv.conf
+        owner: root
+        group: root
+        mode: '0644'
+  when: named_conf.stdout in ('', "0")