# Backup bind9 config and zone files for potential rollback - name: Ensure dir {{bind9_zone_dir}} exists become: true file: path: /srv/dns owner: bind group: bind mode: u+rwx state: directory register: dns_dir_result - set_fact: bind9_initial_setup: "{{dns_dir_result.changed}}" - name: List all existing zone files become: true shell: "find {{ bind9_zone_dir }} -type f -exec basename {} \\;" changed_when: false register: existing_zones_result - debug: "msg={{bind9_initial_setup}}" - debug: "msg={{existing_zones_result}}" - name: Backup /etc/bind/named.conf.local become: true copy: remote_src: true src: /etc/bind/named.conf.local dest: /etc/bind/named.conf.local.bak when: not bind9_initial_setup - name: Backup existing zone files shell: "mv {{bind9_zone_dir}}/{{item}} {{bind9_zone_dir}}/{{item}}.bak" with_items: "{{existing_zones_result.stdout_lines | default([])}}" when: not bind9_initial_setup