mirror of
https://github.com/khuedoan/homelab.git
synced 2025-01-07 05:51:17 +07:00
Render wg0 config file with private key and subnet
This commit is contained in:
parent
26d7fa3e2f
commit
6ef691eca4
@ -7,8 +7,5 @@
|
||||
|
||||
- hosts: all
|
||||
become: yes
|
||||
tasks:
|
||||
- apt:
|
||||
update_cache: yes
|
||||
roles:
|
||||
- name: wireguard
|
||||
|
@ -0,0 +1 @@
|
||||
internal_subnet: 10.13.13.0
|
@ -1,3 +1,7 @@
|
||||
- name: Update apt cache
|
||||
apt:
|
||||
update_cache: yes
|
||||
|
||||
- name: Install Wireguard
|
||||
apt:
|
||||
name: wireguard
|
||||
@ -8,11 +12,16 @@
|
||||
creates: /etc/wireguard/privatekey
|
||||
|
||||
- name: Register private key
|
||||
shell: cat /etc/wireguard/privatekey
|
||||
slurp:
|
||||
src: /etc/wireguard/privatekey
|
||||
register: wireguard_private_key
|
||||
changed_when: false
|
||||
|
||||
- name: Register public key
|
||||
shell: cat /etc/wireguard/publickey
|
||||
slurp:
|
||||
src: /etc/wireguard/publickey
|
||||
register: wireguard_public_key
|
||||
changed_when: false
|
||||
|
||||
- name: Generate wg0 config
|
||||
template:
|
||||
src: wg0.conf.j2
|
||||
dest: /etc/wireguard/wg0.conf
|
||||
|
@ -1,6 +1,6 @@
|
||||
[Interface]
|
||||
Address = {{ interface }}.1
|
||||
Address = {{ internal_subnet | ansible.netcommon.ipmath(1) }}
|
||||
ListenPort = 51820
|
||||
PrivateKey = {{ wireguard_private_key }}
|
||||
PrivateKey = {{ wireguard_private_key['content'] | b64decode }}
|
||||
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
|
||||
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
|
||||
|
Loading…
Reference in New Issue
Block a user