add wireguard role
This commit is contained in:
49
roles/wireguard/templates/wg-multi.conf.j2
Normal file
49
roles/wireguard/templates/wg-multi.conf.j2
Normal file
@ -0,0 +1,49 @@
|
||||
{%- macro render_interface(i) %}
|
||||
[Interface]
|
||||
{% if "private_key" in i %}
|
||||
PrivateKey = {{ i.private_key }}
|
||||
{% endif %}
|
||||
{% if "address" in i %}
|
||||
{% if i.address is string %}
|
||||
Address = {{ i.address }}
|
||||
{% elif i.address is sequence %}
|
||||
{% for address in i.address %}
|
||||
Address = {{ address }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if "listen_port" in i %}
|
||||
ListenPort = {{ i.listen_port }}
|
||||
{% endif %}
|
||||
{% endmacro -%}
|
||||
|
||||
{%- macro render_peer(p) %}
|
||||
{% if "comment" in p %}
|
||||
# {{ p.comment }}
|
||||
{% endif %}
|
||||
[Peer]
|
||||
{% if "public_key" in p %}
|
||||
PublicKey = {{ p.public_key }}
|
||||
{% endif %}
|
||||
{% if "endpoint" in p %}
|
||||
Endpoint = {{ p.endpoint }}
|
||||
{% endif %}
|
||||
{% if "allowed_ips" in p %}
|
||||
{% if p.allowed_ips is string %}
|
||||
AllowedIPs = {{ p.allowed_ips }}
|
||||
{% elif p.allowed_ips is sequence %}
|
||||
AllowedIPs = {{ p.allowed_ips | join(', ') }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endmacro -%}
|
||||
|
||||
{% if wireguard_interfaces[_wireguard_interface] and
|
||||
wireguard_interfaces[_wireguard_interface] is mapping %}
|
||||
{{ render_interface(wireguard_interfaces[_wireguard_interface]) }}
|
||||
{% endif %}
|
||||
{% if wireguard_peers[_wireguard_interface] and
|
||||
wireguard_peers[_wireguard_interface] is sequence %}
|
||||
{% for peer in wireguard_peers[_wireguard_interface] %}
|
||||
{{ render_peer(peer) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
33
roles/wireguard/templates/wg.conf.j2
Normal file
33
roles/wireguard/templates/wg.conf.j2
Normal file
@ -0,0 +1,33 @@
|
||||
[Interface]
|
||||
PrivateKey = {{ wireguard_private_key }}
|
||||
{% if wireguard_address %}
|
||||
{% if wireguard_address is string %}
|
||||
Address = {{ wireguard_address }}
|
||||
{% elif wireguard_address is sequence %}
|
||||
{% for address in wireguard_address %}
|
||||
Address = {{ address }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if wireguard_port %}
|
||||
ListenPort = {{ wireguard_port }}
|
||||
{% endif %}
|
||||
|
||||
{% if wireguard_peers is not string and wireguard_peers is sequence %}
|
||||
{% for peer in wireguard_peers %}
|
||||
[Peer]
|
||||
{% if "public_key" in peer %}
|
||||
PublicKey = {{ peer.public_key }}
|
||||
{% endif %}
|
||||
{% if "endpoint" in peer %}
|
||||
Endpoint = {{ peer.endpoint }}
|
||||
{% endif %}
|
||||
{% if "allowed_ips" in peer %}
|
||||
{% if peer.allowed_ips is string %}
|
||||
AllowedIPs = {{ peer.allowed_ips }}
|
||||
{% elif peer.allowed_ips is sequence %}
|
||||
AllowedIPs = {{ peer.allowed_ips.join(', ') }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
Reference in New Issue
Block a user