diff --git a/tasks/template_zone_files.yml b/tasks/template_zone_files.yml index d738dad..c7fd080 100644 --- a/tasks/template_zone_files.yml +++ b/tasks/template_zone_files.yml @@ -16,7 +16,7 @@ - name: "Template view {{ view.name }}" ansible.builtin.template: src: "{{ inventory_hostname }}/etc/named/{{ zone.file }}.j2" - dest: "{{ bind_config_directory }}/{{ zone.file }}" + dest: "{{ bind_config_directory + '/' + zone.file }}" owner: "{{ bind_unix_user }}" group: "{{ bind_unix_group }}" mode: "0644" @@ -26,3 +26,11 @@ loop_var: zone when: zone.type == 'master' notify: Restart named + +- name: Check if last character in zone files is a newline + ansible.builtin.include_tasks: verify_zone_file.yml + with_items: + - "{{ view.zones }}" + loop_control: + loop_var: zone + when: zone.type == 'master' diff --git a/tasks/verify_zone_file.yml b/tasks/verify_zone_file.yml new file mode 100644 index 0000000..893c3d7 --- /dev/null +++ b/tasks/verify_zone_file.yml @@ -0,0 +1,13 @@ +--- + +- name: "Read the last character of DNS Zonefile: {{ bind_config_directory + '/' + zone.file }}" + ansible.builtin.command: + cmd: "tail --bytes 1 {{ bind_config_directory + '/' + zone.file }}" + register: _bind9_zone_last_character + changed_when: _bind9_zone_last_character.rc == 0 + failed_when: _bind9_zone_last_character.rc > 0 + +- name: "Fail when the last character of DNS zone file is not a newline: {{ bind_config_directory + '/' + zone.file }}" + ansible.builtin.fail: + msg: "Last character of DNS zone file is not a newline: {{ bind_config_directory + '/' + zone.file }}" + failed_when: _bind9_zone_last_character.stdout | regex_search('.+') | default(false)