initial commit
This commit is contained in:
commit
43e8780420
7 changed files with 62 additions and 0 deletions
9
defaults/main.yml
Normal file
9
defaults/main.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
wireguard:
|
||||||
|
defaults:
|
||||||
|
lport: 51820
|
||||||
|
privkey: ''
|
||||||
|
ip: []
|
||||||
|
ip6: []
|
||||||
|
peers: {}
|
||||||
|
connections: {}
|
||||||
|
|
||||||
3
meta/main.yml
Normal file
3
meta/main.yml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
dependencies:
|
||||||
|
- { role: packages }
|
||||||
11
tasks/main.yml
Normal file
11
tasks/main.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
- name: install wireguard
|
||||||
|
package:
|
||||||
|
name:
|
||||||
|
- wireguard
|
||||||
|
- wireguard-tools
|
||||||
|
|
||||||
|
- name: handle a wireguard network
|
||||||
|
include_tasks: net.yml
|
||||||
|
loop: "{{ wireguard.connections|dict2items }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: conn
|
||||||
12
tasks/net.yml
Normal file
12
tasks/net.yml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
- set_fact:
|
||||||
|
item: "{{ {}|combine(wireguard.defaults , {'name': conn.name}, item.value, recursive=True) }}"
|
||||||
|
|
||||||
|
- name: generate interface config
|
||||||
|
template:
|
||||||
|
src: networkinterface.j2
|
||||||
|
dest: /etc/network/interfaces.d/wg_{{ item.name }}
|
||||||
|
|
||||||
|
- name: generate wireguard config
|
||||||
|
template:
|
||||||
|
src: wireguard.conf.j2
|
||||||
|
dest: /etc/wireguard//wg_{{ item.name }}
|
||||||
14
templates/networkinterface.j2
Normal file
14
templates/networkinterface.j2
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
auto wg_{{ item.name }}
|
||||||
|
iface w_{{ item.name }} inet static
|
||||||
|
{% for i in item.ip %}
|
||||||
|
address {{ i }}
|
||||||
|
{% endif %}
|
||||||
|
pre-up ip link add $IFACE type wireguard
|
||||||
|
pre-up wg setconf $IFACE /etc/wireguard/$IFACE.conf
|
||||||
|
post-down ip link del $IFACE
|
||||||
|
|
||||||
|
iface w_{{ item.name }} inet6 static
|
||||||
|
# static IP address
|
||||||
|
{% for i in item.ip6 %}
|
||||||
|
address {{ i }}
|
||||||
|
{% endif %}
|
||||||
11
templates/wireguard.conf.j2
Normal file
11
templates/wireguard.conf.j2
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
[Interface]
|
||||||
|
Address = {{ (item.ip + item.ip6)|join(', ') }}
|
||||||
|
ListenPort = {{ item.lport }}
|
||||||
|
PrivateKey = {{ item.privkey }}
|
||||||
|
|
||||||
|
{% for peer in item.peers %}
|
||||||
|
[Peer]
|
||||||
|
PublicKey = {{ peer.PublicKey }}
|
||||||
|
AllowedIPs = {{ peer.AllowedIPs|join(', ') }}
|
||||||
|
{% if peer.Endpoint is defined %}Endpoint = {{ peer.Endpoint }}{% endif %}
|
||||||
|
{% endfor %}
|
||||||
2
vars/main.yml
Normal file
2
vars/main.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
packages:
|
||||||
|
repos: '{% if ansible_distribution_release|lower =="buster" %}{ "buster-backports": { "url": "deb http://deb.debian.org/debian buster-backports main" } }{% else %}{}{% endif %}'
|
||||||
Loading…
Add table
Add a link
Reference in a new issue