Work around a jinja2 bug in the map filter regarding default values (https://github.com/pallets/jinja/issues/1331)

This commit is contained in:
s3lph 2021-02-05 22:28:20 +01:00
parent 3200fe522a
commit 47bf844bf1

View file

@ -24,16 +24,18 @@ log:
# #
key: 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 }} - id: {{ hostvars[remote].knot_tsig_key.name }}
algorithm: {{ hostvars[remote].knot_tsig_key.algorithm }} algorithm: {{ hostvars[remote].knot_tsig_key.algorithm }}
secret: {{ hostvars[remote].knot_tsig_key.secret }} secret: {{ hostvars[remote].knot_tsig_key.secret }}
{% endif %}
{% endfor %} {% endfor %}
remote: 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 }} - id: remote-{{ remote }}
{% for address in hostvars[remote].knot_dns_addresses %} {% for address in hostvars[remote].knot_dns_addresses %}
@ -46,7 +48,7 @@ acl:
- id: acl-xfr-{{ remote }} - id: acl-xfr-{{ remote }}
action: transfer action: transfer
{% if knot_tsig_key in hostvars[remote] %} {% if 'knot_tsig_key' in hostvars[remote] %}
key: {{ hostvars[remote].knot_tsig_key.name }} key: {{ hostvars[remote].knot_tsig_key.name }}
{% else %} {% else %}
{% for address in hostvars[remote].knot_dns_addresses %} {% for address in hostvars[remote].knot_dns_addresses %}
@ -59,7 +61,7 @@ acl:
- id: acl-notify-{{ remote }} - id: acl-notify-{{ remote }}
action: notify action: notify
{% if knot_tsig_key in hostvars[remote] %} {% if 'knot_tsig_key' in hostvars[remote] %}
key: {{ hostvars[remote].knot_tsig_key.name }} key: {{ hostvars[remote].knot_tsig_key.name }}
{% else %} {% else %}
{% for address in hostvars[remote].knot_dns_addresses %} {% for address in hostvars[remote].knot_dns_addresses %}
@ -68,7 +70,7 @@ acl:
{% endif %} {% endif %}
{% endfor %} {% 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 }} - id: acl-update-{{ remote }}
action: update action: update