Files
Christian Heusel 797acabb26 wireguard: Make missing hostvar failure more readable
Previously the error message was missing the proper context to
understand which host did not have the host variable defined:

    Task failed: object of type 'HostVarsVars' has no attribute 'wireguard_public_key'

With the changes from this commit this error becomes much more readable:

    Task failed: The filter plugin 'ansible.builtin.mandatory' failed: bastion.archlinux.org is missing mandatory host var wireguard_public_key

Signed-off-by: Christian Heusel <christian@heusel.eu>
2026-01-04 13:58:57 +01:00

21 lines
740 B
Django/Jinja

[NetDev]
Name=wg0
Kind=wireguard
[WireGuard]
ListenPort=51820
PrivateKey=@network.wireguard.private.wg0
{% for host in groups['all'] if host != inventory_hostname %}
# {{ host }}
[WireGuardPeer]
PublicKey={{ hostvars[host]['wireguard_public_key'] | mandatory(host + ' is missing mandatory host var wireguard_public_key') }}
AllowedIPs={{ hostvars[host]['wireguard_address'] | mandatory(host + ' is missing mandatory host var wireguard_address') }}/32
{% if hostvars[host]['ansible_host'] is defined and (hostvars[host]['nginx_proxy_protocol_upstream_host'] is defined or hostvars[host]['nginx_proxy_vendor'] is defined) %}
Endpoint={{ hostvars[host]['ansible_host'] }}:51820
{% else %}
Endpoint={{ host }}:51820
{% endif %}
{% endfor %}