stat:
path: "/etc/bind/{{ domain }}"
register: domain_exists
+ changed_when: not domain_exists.stat.exists
-- name: Copy domain template
- become: true
- template:
- src: domain
- dest: "/etc/bind/{{ domain }}"
- owner: bind
- group: bind
- mode: '0600'
- force: no
- when: not domain_exists.stat.exists
-
-- name: Update config
- become: true
- shell: |
-echo '
+- block:
+ - name: Copy domain template
+ become: true
+ template:
+ src: domain
+ dest: "/etc/bind/{{ domain }}"
+ owner: bind
+ group: bind
+ mode: '0600'
+ force: no
-zone "{{ domain }}" {
- type master;
- file "/etc/bind/{{ domain }}";
- allow-query { any; };
- notify yes;
-};
-' >> /etc/bind/named.conf.local
+ - name: Update config
+ become: true
+ shell: |
+ echo 'zone "{{ domain }}" {
+ type master;
+ file "/etc/bind/{{ domain }}";
+ allow-query { any; };
+ notify yes;
+ };' >> /etc/bind/named.conf.local
- when: not domain_exists.stat.exists
+ - name: Update resolver config
+ become: true
+ lineinfile:
+ path: /etc/resolv.conf
+ regexp: "^domain {{ domain }}"
+ line: "domain {{ domain }}"
-- name: Reload BIND
- become: true
- service:
- name: bind9
- state: reloaded
+ - name: Reload BIND
+ become: true
+ service:
+ name: bind9
+ state: reloaded
when: not domain_exists.stat.exists