bind9-ansible-role/tasks/02-backup.yml

38 lines
977 B
YAML
Raw Permalink Normal View History

2021-12-27 20:58:01 +01:00
# Backup bind9 config and zone files for potential rollback
- name: Ensure dir {{bind9_zone_dir}} exists
2021-12-27 21:07:43 +01:00
become: true
2021-12-27 20:58:01 +01:00
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
2021-12-27 21:07:43 +01:00
become: true
2021-12-27 20:58:01 +01:00
shell: "find {{ bind9_zone_dir }} -type f -exec basename {} \\;"
changed_when: false
register: existing_zones_result
- debug: "msg={{bind9_initial_setup}}"
2021-12-27 21:55:55 +01:00
- debug: "msg={{existing_zones_result}}"
2021-12-27 20:58:01 +01:00
- 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([])}}"
2021-12-27 20:58:01 +01:00
when: not bind9_initial_setup