Make wireguard role generic
This commit is contained in:
parent
05b13685e4
commit
d39ea3b25f
5 changed files with 33 additions and 8 deletions
12
roles/wireguard/meta/argument_specs.yml
Normal file
12
roles/wireguard/meta/argument_specs.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
argument_specs:
|
||||
main:
|
||||
options:
|
||||
interface:
|
||||
type: str
|
||||
listen_port:
|
||||
type: int
|
||||
address:
|
||||
type: str
|
||||
peers:
|
||||
type: list
|
|
@ -10,7 +10,8 @@
|
|||
ansible.builtin.file:
|
||||
path: /etc/wireguard
|
||||
state: directory
|
||||
mode: '1750'
|
||||
mode: '1700'
|
||||
owner: root
|
||||
- name: Generate private key
|
||||
become: true
|
||||
ansible.builtin.shell: |
|
||||
|
@ -44,9 +45,10 @@
|
|||
ansible.builtin.template:
|
||||
src: wg0.conf.j2
|
||||
dest: /etc/wireguard/wg0.conf
|
||||
register: cfg
|
||||
- name: Enable wireguard service
|
||||
become: true
|
||||
ansible.builtin.systemd_service:
|
||||
name: wg-quick@wg0
|
||||
state: restarted
|
||||
state: "{% if cfg.changed %}restarted{% else %}started{% endif %}"
|
||||
enabled: true
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
[Interface]
|
||||
PrivateKey = {{ private_key.content | b64decode }}
|
||||
Address = 10.110.0.1/24
|
||||
ListenPort = 51840
|
||||
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o ens18 -j MASQUERADE
|
||||
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o ens18 -j MASQUERADE
|
||||
Address = {{ address }}
|
||||
ListenPort = {{ listen_port }}
|
||||
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o {{ interface }} -j MASQUERADE
|
||||
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o {{ interface }} -j MASQUERADE
|
||||
|
||||
{% for peer in peers %}
|
||||
[Peer]
|
||||
PublicKey = awAVP/tkl0Z9PKEMTABjIXhblWSGHhIvYjBFp3C7YUk=
|
||||
AllowedIPs = 10.110.0.2/32
|
||||
PublicKey = {{ peer.public_key }}
|
||||
AllowedIPs = {{ peer.allowed_ips }}
|
||||
{% endfor %}
|
||||
|
|
4
roles/wireguard/vars/main.yml
Normal file
4
roles/wireguard/vars/main.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
interface: ens18
|
||||
listen_port: 51820
|
||||
address: 10.0.0.1/8
|
||||
peers: []
|
|
@ -2,3 +2,8 @@
|
|||
- hosts: network
|
||||
roles:
|
||||
- role: wireguard
|
||||
address: 10.110.0.1/24
|
||||
listen_port: 51840
|
||||
peers:
|
||||
- public_key: awAVP/tkl0Z9PKEMTABjIXhblWSGHhIvYjBFp3C7YUk=
|
||||
allowed_ips: 10.110.0.2/32
|
||||
|
|
Loading…
Reference in a new issue