- name: Check domain stat: path: "/etc/bind/{{ domain }}" register: domain_exists changed_when: not domain_exists.stat.exists - block: - name: Copy domain template become: true template: src: domain dest: "/etc/bind/{{ domain }}" owner: bind group: bind mode: '0600' force: no - 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 - 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 when: not domain_exists.stat.exists