3
0
Fork 0

Compare commits

...

9 Commits

5 changed files with 42 additions and 30 deletions

View File

@ -1,3 +1,5 @@
# Fork of https://github.com/githubixx/ansible-role-wireguard.git with some minor tweaks to ensure PiFrameFleet can be provisioned properly
ansible-role-wireguard
======================

View File

@ -12,6 +12,9 @@ wireguard_port: "51820"
# The default interface name that wireguard should use if not specified otherwise.
wireguard_interface: "wg0"
# Whether or not WireGuard is running in a container
wireguard_containerized: false
#######################################
# Settings only relevant for Ubuntu

View File

@ -6,7 +6,7 @@
loop:
- stopped
- started
when: not wg_syncconf
when: not wg_syncconf and not wireguard_containerized
listen: "reconfigure wireguard"
- name: syncconf wireguard
@ -19,5 +19,10 @@
exit 0
args:
executable: "/bin/bash"
when: wg_syncconf
when: wg_syncconf and not wireguard_containerized
listen: "reconfigure wireguard"
- name: restart wireguard (container)
command: /usr/bin/s6-svc -r /var/run/s6/services/wireguard
when: wireguard_containerized
listen: "reconfigure wireguard"

View File

@ -3,6 +3,7 @@
setup:
- include_tasks: "setup-{{ ansible_distribution|lower }}.yml"
when: not wireguard_containerized
- name: Enable WireGuard kernel module
modprobe:
@ -129,3 +130,4 @@
name: "wg-quick@{{ wireguard_interface }}"
state: started
enabled: yes
when: not wireguard_containerized

View File

@ -39,32 +39,32 @@ PostDown = {{ wg_postdown }}
{% if hostvars[inventory_hostname].wireguard_save_config is defined %}
SaveConfig = true
{% endif %}
{% for host in ansible_play_hosts %}
{% if host != inventory_hostname %}
[Peer]
# {{ host }}
PublicKey = {{hostvars[host].public_key}}
{% if hostvars[host].wireguard_allowed_ips is defined %}
AllowedIPs = {{hostvars[host].wireguard_allowed_ips}}
{% else %}
AllowedIPs = {{hostvars[host].wireguard_ip}}/32
{% endif %}
{% if hostvars[host].wireguard_persistent_keepalive is defined %}
PersistentKeepalive = {{hostvars[host].wireguard_persistent_keepalive}}
{% endif %}
{% if hostvars[host].wireguard_port is defined and hostvars[host].wireguard_port is number %}
{% 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 %}
{% elif hostvars[host].wireguard_endpoint is defined and hostvars[host].wireguard_endpoint != "" %}
Endpoint = {{hostvars[host].wireguard_endpoint}}:{{wireguard_port}}
{% elif hostvars[host].wireguard_endpoint == "" %}
# No endpoint defined for this peer
{% else %}
Endpoint = {{host}}:{{wireguard_port}}
{% endif %}
{% endif %}
{% for host in ansible_play_hosts_all %}
{% if host != inventory_hostname %}
[Peer]
# {{ host }}
PublicKey = {{hostvars[host].public_key}}
{% if hostvars[host].wireguard_allowed_ips is defined %}
AllowedIPs = {{hostvars[host].wireguard_allowed_ips}}
{% else %}
AllowedIPs = {{hostvars[host].wireguard_ip}}/32
{% endif %}
{% if hostvars[host].wireguard_persistent_keepalive is defined %}
PersistentKeepalive = {{hostvars[host].wireguard_persistent_keepalive}}
{% endif %}
{% if hostvars[host].wireguard_port is defined and hostvars[host].wireguard_port is number %}
{% 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 %}
{% elif hostvars[host].wireguard_endpoint is defined and hostvars[host].wireguard_endpoint != "" %}
Endpoint = {{hostvars[host].wireguard_endpoint}}:{{wireguard_port}}
{% elif hostvars[host].wireguard_endpoint == "" %}
# No endpoint defined for this peer
{% else %}
Endpoint = {{host}}:{{wireguard_port}}
{% endif %}
{% endif %}
{% endfor %}