From 47bf844bf1787c24a42b07109d1874f23fa660cc Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 5 Feb 2021 22:28:20 +0100 Subject: [PATCH] Work around a jinja2 bug in the map filter regarding default values (https://github.com/pallets/jinja/issues/1331) --- roles/knot/templates/etc/knot/knot.conf.j2 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/roles/knot/templates/etc/knot/knot.conf.j2 b/roles/knot/templates/etc/knot/knot.conf.j2 index ee49875..e0d3a26 100644 --- a/roles/knot/templates/etc/knot/knot.conf.j2 +++ b/roles/knot/templates/etc/knot/knot.conf.j2 @@ -24,16 +24,18 @@ log: # key: -{% for remote in ( (zones | map(attribute='replicas') ) + (zones | map(attribute='masters') ) + (zones | map(attribute='updaters', default=[]) ) ) | flatten | unique %} +{% for remote in ( (zones | map(attribute='replicas') ) + (zones | map(attribute='masters') ) + (zones | map(attribute='updaters') | select('defined') ) ) | flatten | unique %} +{% if 'knot_tsig_key' in hostvars[remote] %} - id: {{ hostvars[remote].knot_tsig_key.name }} algorithm: {{ hostvars[remote].knot_tsig_key.algorithm }} secret: {{ hostvars[remote].knot_tsig_key.secret }} +{% endif %} {% endfor %} remote: -{% for remote in ( (zones | map(attribute='replicas') ) + (zones | map(attribute='masters') ) + (zones | map(attribute='updaters', default=[]) ) ) | flatten | unique %} +{% for remote in ( (zones | map(attribute='replicas') ) + (zones | map(attribute='masters') ) + (zones | map(attribute='updaters') | select('defined') ) ) | flatten | unique %} - id: remote-{{ remote }} {% for address in hostvars[remote].knot_dns_addresses %} @@ -46,7 +48,7 @@ acl: - id: acl-xfr-{{ remote }} action: transfer -{% if knot_tsig_key in hostvars[remote] %} +{% if 'knot_tsig_key' in hostvars[remote] %} key: {{ hostvars[remote].knot_tsig_key.name }} {% else %} {% for address in hostvars[remote].knot_dns_addresses %} @@ -59,7 +61,7 @@ acl: - id: acl-notify-{{ remote }} action: notify -{% if knot_tsig_key in hostvars[remote] %} +{% if 'knot_tsig_key' in hostvars[remote] %} key: {{ hostvars[remote].knot_tsig_key.name }} {% else %} {% for address in hostvars[remote].knot_dns_addresses %} @@ -68,7 +70,7 @@ acl: {% endif %} {% endfor %} -{% for remote in zones | map(attribute='updaters', default=[]) | flatten | unique %} +{% for remote in zones | map(attribute='updaters') | select('defined') | flatten | unique %} - id: acl-update-{{ remote }} action: update