diff --git a/roles/knot/tasks/config.yml b/roles/knot/tasks/config.yml index cd920a7..d37312e 100644 --- a/roles/knot/tasks/config.yml +++ b/roles/knot/tasks/config.yml @@ -1,47 +1,5 @@ --- -- name: create knot zone directories - file: - path: "{{ item }}" - state: directory - owner: knot - group: knot - mode: 0750 - loop: - - "{{ knot_zone_master_storage_path }}" - - "{{ knot_zone_replica_storage_path }}" - -- name: make sure all zones have a name - assert: - that: - - "'name' in item.value" - - "item.value.name | type_debug == 'str'" - fail_msg: "{{ item.key }} does not have a name" - loop: "{{ hostvars[inventory_hostname] | dict2items | selectattr('key', 'match', '^knot_zone_.+$') | list }}" - -- name: make sure all zones have at least one master defined - assert: - that: - - "'masters' in item.value" - - "item.value.masters | type_debug == 'list'" - - "item.value.masters | length > 0" - fail_msg: "{{ item.key }} does not have a zone master" - loop: "{{ hostvars[inventory_hostname] | dict2items | selectattr('key', 'match', '^knot_zone_.+$') | list }}" - -- name: render knot zone files - template: - src: var/lib/knot/master/zone.j2 - dest: "{{ knot_zone_master_storage_path }}/{{ item.name }}zone" - owner: knot - group: knot - mode: 0640 - validate: /usr/bin/kzonecheck -v %s - vars: - zone: "{{ item }}" - when: "inventory_hostname in item['masters']" - loop: "{{ hostvars[inventory_hostname] | dict2items | selectattr('key', 'match', '^knot_zone_.+$') | map(attribute='value') | list }}" - notify: reload knot - - name: render knot master config template: src: etc/knot/knot.conf.j2 diff --git a/roles/knot/tasks/main.yml b/roles/knot/tasks/main.yml index 0995b3f..85e1063 100644 --- a/roles/knot/tasks/main.yml +++ b/roles/knot/tasks/main.yml @@ -6,6 +6,12 @@ - "role::knot" - "role::knot:install" +- name: render zonefiles + import_tasks: zones.yml + tags: + - "role::knot" + - "role::knot:zones" + - name: configure knot import_tasks: config.yml tags: diff --git a/roles/knot/tasks/zones.yml b/roles/knot/tasks/zones.yml new file mode 100644 index 0000000..c1fd06e --- /dev/null +++ b/roles/knot/tasks/zones.yml @@ -0,0 +1,43 @@ +--- + +- name: create knot zone directories + file: + path: "{{ item }}" + state: directory + owner: knot + group: knot + mode: 0750 + loop: + - "{{ knot_zone_master_storage_path }}" + - "{{ knot_zone_replica_storage_path }}" + +- name: make sure all zones have a name + assert: + that: + - "'name' in item.value" + - "item.value.name | type_debug == 'str'" + fail_msg: "{{ item.key }} does not have a name" + loop: "{{ hostvars[inventory_hostname] | dict2items | selectattr('key', 'match', '^knot_zone_.+$') | list }}" + +- name: make sure all zones have at least one master defined + assert: + that: + - "'masters' in item.value" + - "item.value.masters | type_debug == 'list'" + - "item.value.masters | length > 0" + fail_msg: "{{ item.key }} does not have a zone master" + loop: "{{ hostvars[inventory_hostname] | dict2items | selectattr('key', 'match', '^knot_zone_.+$') | list }}" + +- name: render knot zone files + template: + src: var/lib/knot/master/zone.j2 + dest: "{{ knot_zone_master_storage_path }}/{{ item.name }}zone" + owner: knot + group: knot + mode: 0640 + validate: /usr/bin/kzonecheck -v %s + vars: + zone: "{{ item }}" + when: "inventory_hostname in item['masters']" + loop: "{{ hostvars[inventory_hostname] | dict2items | selectattr('key', 'match', '^knot_zone_.+$') | map(attribute='value') | list }}" + notify: reload knot