- name: setup coredns gather_facts: no hosts: "{{target}}" become: "{{become}}" tasks: - name: check coredns is installed ansible.builtin.shell: executable: /bin/bash cmd: "[[ -x `which coredns` ]]" changed_when: false check_mode: false - name: check for coredns unit file ansible.builtin.shell: executable: /bin/bash cmd: "[[ -f /etc/systemd/system/coredns.service ]]" changed_when: false check_mode: false # primary - name: coredns primary config file ansible.builtin.template: src: Corefile.primary.j2 dest: /etc/coredns/Corefile diff: true notify: restart-coredns when: ns_type == 'primary' # todo - fileglob catch all existing zonefile domains - name: domain zone file ansible.builtin.template: src: zone-file.j2 dest: /etc/coredns/{{domain}}.db.tpl diff: true notify: incr-n-restart-coredns when: ns_type == 'primary' # secondary - name: coredns secondary config file ansible.builtin.template: src: Corefile.secondary.j2 dest: /etc/coredns/Corefile diff: true notify: restart-coredns when: ns_type == 'secondary' # shared # we might do old-school active/active at some point # keep the script available on another primary to be... - name: deploy incr script ansible.builtin.copy: src: incr.bash dest: /root/incr.bash mode: 0700 diff: true - name: handy wrapper for logs ansible.builtin.copy: src: logcoredns dest: /root/logcoredns mode: 0755 diff: true handlers: - name: incr-n-restart-coredns ansible.builtin.shell: executable: /bin/bash cmd: /root/incr.bash {{domain}} && systemctl restart coredns.service - name: restart-coredns ansible.builtin.shell: executable: /bin/bash cmd: systemctl restart coredns.service