๐Ÿ“— Ansible playbooks and roles for building an idempotent, interconnected and scalable infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
ansible-playbooks/roles/coredns/tasks/increase_serial.yml

53 lines
1.4 KiB

- name: fail if zone is not defined
fail:
msg: zone is not defined
when: zone is not defined
- name: slurp zone file
slurp:
src: "{{ (coredns_conf_dir, zone ~ '.zone') | path_join }}"
register: zf
changed_when: no
- name: get SOA serial value
set_fact:
ns_old_serial: '{{ zf.content | b64decode | regex_search(''@\s+IN\s+SOA\s+\S+\s+\S+\s*\(\s*(\d+)'', ''\1'') | first | string }}'
- name: get current date
include_tasks: tasks/get_datetime.yml
vars:
format: YYMMDD
- name: replace outdated serial with current date
set_fact:
ns_new_serial: "{{ (current_date_time | string) ~ '01'}}"
when: ns_old_serial[:8] != (current_date_time | string)
- name: increase current serial
set_fact:
ns_new_serial: "{{ (ns_old_serial | int) + 1 }}"
when: (ns_old_serial[:8] == (current_date_time | string)) and ((ns_old_serial[8:10] | int) < 99)
- name: do not change current serial if it had more than 99 iterations
set_fact:
ns_new_serial: "{{ ns_old_serial }}"
when: (ns_old_serial[:8] == (current_date_time | string)) and ((ns_old_serial[8:10] | int) >= 99)
- name: insert new serial
replace:
path: "{{ (coredns_conf_dir, zone ~ '.zone') | path_join }}"
regexp: '(@\s+IN\s+SOA\s+\S+\s+\S+\s*\(\s*){{ ns_old_serial }}'
replace: '\g<1>{{ ns_new_serial }}'
register: result
- name: set fact if serial was changed
set_fact:
ns_serial_changed: "{{ result.changed }}"