2018-08-12 22:21:45 +02:00
|
|
|
#jinja2: lstrip_blocks:"True",trim_blocks:"True"
|
2022-05-05 00:03:25 +02:00
|
|
|
{# Copyright (C) 2018-2022 Robert Wimmer
|
2020-10-11 23:04:28 +02:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#}
|
2020-09-13 23:02:57 +02:00
|
|
|
# {{ ansible_managed }}
|
|
|
|
|
2018-08-12 22:21:45 +02:00
|
|
|
[Interface]
|
2019-11-05 22:55:04 +01:00
|
|
|
# {{ inventory_hostname }}
|
2020-09-19 21:37:33 +02:00
|
|
|
Address = {{ wireguard_address }}
|
2020-10-12 23:07:02 +02:00
|
|
|
PrivateKey = {{ wireguard_private_key }}
|
2020-09-13 23:00:10 +02:00
|
|
|
ListenPort = {{ wireguard_port }}
|
2020-09-19 21:31:11 +02:00
|
|
|
{% if wireguard_dns is defined %}
|
2020-09-19 21:37:33 +02:00
|
|
|
DNS = {{ wireguard_dns }}
|
2018-08-12 22:21:45 +02:00
|
|
|
{% endif %}
|
2020-09-19 21:31:11 +02:00
|
|
|
{% if wireguard_fwmark is defined %}
|
2020-09-19 21:37:33 +02:00
|
|
|
FwMark = {{ wireguard_fwmark }}
|
2019-11-05 22:55:04 +01:00
|
|
|
{% endif %}
|
2020-09-19 21:31:11 +02:00
|
|
|
{% if wireguard_mtu is defined %}
|
2020-09-19 21:37:33 +02:00
|
|
|
MTU = {{ wireguard_mtu }}
|
2019-11-05 22:55:04 +01:00
|
|
|
{% endif %}
|
2020-09-19 21:31:11 +02:00
|
|
|
{% if wireguard_table is defined %}
|
2020-09-19 21:37:33 +02:00
|
|
|
Table = {{ wireguard_table }}
|
2019-11-05 22:55:04 +01:00
|
|
|
{% endif %}
|
2020-09-19 21:31:11 +02:00
|
|
|
{% if wireguard_preup is defined %}
|
|
|
|
{% for wg_preup in wireguard_preup %}
|
2020-01-20 21:07:08 +01:00
|
|
|
PreUp = {{ wg_preup }}
|
|
|
|
{% endfor %}
|
2019-11-05 22:55:04 +01:00
|
|
|
{% endif %}
|
2020-09-19 21:31:11 +02:00
|
|
|
{% if wireguard_postup is defined %}
|
|
|
|
{% for wg_postup in wireguard_postup %}
|
2020-01-20 21:07:08 +01:00
|
|
|
PostUp = {{ wg_postup }}
|
|
|
|
{% endfor %}
|
2018-08-12 22:21:45 +02:00
|
|
|
{% endif %}
|
2022-01-14 23:43:04 +01:00
|
|
|
{% if wireguard_predown is defined %}
|
|
|
|
{% for wg_predown in wireguard_predown %}
|
|
|
|
PreDown = {{ wg_predown }}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2020-09-19 21:31:11 +02:00
|
|
|
{% if wireguard_postdown is defined %}
|
|
|
|
{% for wg_postdown in wireguard_postdown %}
|
2020-01-20 21:07:08 +01:00
|
|
|
PostDown = {{ wg_postdown }}
|
|
|
|
{% endfor %}
|
2018-08-12 22:21:45 +02:00
|
|
|
{% endif %}
|
2020-09-19 21:31:11 +02:00
|
|
|
{% if wireguard_save_config is defined %}
|
2022-02-17 22:55:25 +01:00
|
|
|
SaveConfig = {{ wireguard_save_config }}
|
2018-08-12 22:21:45 +02:00
|
|
|
{% endif %}
|
2019-11-02 20:39:47 +01:00
|
|
|
{% for host in ansible_play_hosts %}
|
2020-09-22 23:37:00 +02:00
|
|
|
{% if host != inventory_hostname %}
|
2020-10-11 23:04:28 +02:00
|
|
|
|
2020-09-22 23:37:00 +02:00
|
|
|
[Peer]
|
|
|
|
# {{ host }}
|
2020-09-13 23:00:10 +02:00
|
|
|
PublicKey = {{hostvars[host].wireguard__fact_public_key}}
|
2020-09-22 23:37:00 +02:00
|
|
|
{% if hostvars[host].wireguard_allowed_ips is defined %}
|
|
|
|
AllowedIPs = {{hostvars[host].wireguard_allowed_ips}}
|
|
|
|
{% else %}
|
2020-09-20 00:39:14 +02:00
|
|
|
AllowedIPs = {{ hostvars[host].wireguard_address.split('/')[0] }}/32
|
2020-09-22 23:37:00 +02:00
|
|
|
{% endif %}
|
|
|
|
{% if hostvars[host].wireguard_persistent_keepalive is defined %}
|
|
|
|
PersistentKeepalive = {{hostvars[host].wireguard_persistent_keepalive}}
|
|
|
|
{% endif %}
|
|
|
|
{% if (
|
|
|
|
hostvars[host].wireguard_dc is defined and
|
2020-09-19 21:31:11 +02:00
|
|
|
wireguard_dc is defined and
|
|
|
|
wireguard_dc['name'] != hostvars[host].wireguard_dc['name']
|
2020-09-22 23:37:00 +02:00
|
|
|
)
|
|
|
|
%}
|
|
|
|
Endpoint = {{hostvars[host].wireguard_dc['endpoint']}}:{{hostvars[host].wireguard_dc['port']}}
|
2022-01-16 14:53:58 -05:00
|
|
|
{% elif hostvars[host].wireguard_port is defined %}
|
2020-09-22 23:37:00 +02:00
|
|
|
{% if hostvars[host].wireguard_endpoint is defined and hostvars[host].wireguard_endpoint != "" %}
|
|
|
|
Endpoint = {{hostvars[host].wireguard_endpoint}}:{{hostvars[host].wireguard_port}}
|
|
|
|
{% else %}
|
|
|
|
Endpoint = {{host}}:{{hostvars[host].wireguard_port}}
|
|
|
|
{% endif %}
|
2021-04-08 15:18:05 -06:00
|
|
|
{% elif hostvars[host].wireguard_endpoint is defined %}
|
|
|
|
{% if hostvars[host].wireguard_endpoint != "" %}
|
2020-09-22 23:37:00 +02:00
|
|
|
Endpoint = {{hostvars[host].wireguard_endpoint}}:{{wireguard_port}}
|
2021-04-08 15:18:05 -06:00
|
|
|
{% else %}
|
2020-09-22 23:37:00 +02:00
|
|
|
# No endpoint defined for this peer
|
2021-04-08 15:18:05 -06:00
|
|
|
{% endif %}
|
2020-09-22 23:37:00 +02:00
|
|
|
{% else %}
|
|
|
|
Endpoint = {{host}}:{{wireguard_port}}
|
|
|
|
{% endif %}
|
|
|
|
{% endif %}
|
2018-08-12 22:21:45 +02:00
|
|
|
{% endfor %}
|
2020-09-15 22:58:04 +03:00
|
|
|
{% if wireguard_unmanaged_peers is defined %}
|
|
|
|
|
2020-09-22 23:37:00 +02:00
|
|
|
# Peers not managed by Ansible from "wireguard_unmanaged_peers" variable
|
|
|
|
{% for peer in wireguard_unmanaged_peers.keys() %}
|
|
|
|
[Peer]
|
|
|
|
# {{ peer }}
|
|
|
|
PublicKey = {{ wireguard_unmanaged_peers[peer].public_key }}
|
|
|
|
{% if wireguard_unmanaged_peers[peer].preshared_key is defined %}
|
|
|
|
PresharedKey = {{ wireguard_unmanaged_peers[peer].preshared_key }}
|
|
|
|
{% endif %}
|
|
|
|
{% if wireguard_unmanaged_peers[peer].allowed_ips is defined %}
|
|
|
|
AllowedIPs = {{ wireguard_unmanaged_peers[peer].allowed_ips }}
|
|
|
|
{% endif %}
|
|
|
|
{% if wireguard_unmanaged_peers[peer].endpoint is defined %}
|
|
|
|
Endpoint = {{ wireguard_unmanaged_peers[peer].endpoint }}
|
|
|
|
{% endif %}
|
|
|
|
{% if wireguard_unmanaged_peers[peer].persistent_keepalive is defined %}
|
|
|
|
PersistentKeepalive = {{ wireguard_unmanaged_peers[peer].persistent_keepalive }}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
2020-09-15 22:58:04 +03:00
|
|
|
{% endif %}
|