๐Ÿ“— 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

48 lines
1.3 KiB

2 years ago
- name: slurp zone file
slurp:
src: "{{ coredns_conf_dir ~ '/' ~ (ns_tld | d(int_tld)) ~ '.zone' }}"
register: zf
changed_when: false
- 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 }}'
- 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 ~ '/' ~ (ns_tld | d(int_tld)) ~ '.zone' }}"
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 }}"