[Interface]
Address = {{ wireguard_address }}
PrivateKey = {{ wireguard_private_key }}
ListenPort = {{ wireguard_port }}

{% for host in wireguard_peers %}
{% if host != inventory_hostname %}
[Peer]
# {{ host }}
PublicKey = {{ hostvars[host]['wireguard_public_key'] }}
AllowedIPs = {{ hostvars[host]['wireguard_address'].split('/')[0] }}/32
Endpoint = {{ hostvars[host]['ansible_host'] | default(host) }}:{{ hostvars[host]['wireguard_port'] | default(wireguard_port) }}
PersistentKeepalive = {{ wireguard_keepalive }}

{% endif %}
{% endfor %}
