about summary refs log tree commit diff
path: root/wireguard.yml
blob: be40d5b675efb651a74a4ec1da6e6c28017c3f07 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
- name: Wireguard config
  hosts: tamriel
  remote_user: ansible_worker
  become: yes
  vars_files:
  - secrets.yml
  tasks:
  - name: install wireguard
    apt:
      name: wireguard
  - name: IPv4 forwarding
    sysctl:
      name: net.ipv4.ip_forward
      value: "1"
      state: present
  - name: ARP proxy
    sysctl:
      name: net.ipv4.conf.all.proxy_arp
      value: "1"
      state: present

  - name: Enable systemd-networkd
    systemd:
      enabled: true
      state: started
      name: systemd-networkd

  - name: Generate wireguard config
    template:
      src: templates/wg.netdev.j2
      dest: /etc/systemd/network/30-wg0.netdev
      owner: root
      group: systemd-network
      mode: "640"
  - name: Generate networkd config
    template:
      src: templates/wg.network.j2
      dest: /etc/systemd/network/30-wg0.network

  - name: Remove interface #systemd-networkd doesn't reload netdev
    shell: ip link del dev wg0 || true

      
  - name: Restart systemd-networkd
    systemd:
      state: restarted
      name: systemd-networkd

  - iptables:
      chain: INPUT
      match: conntrack
      ctstate: ["RELATED","ESTABLISHED"]
      jump: ACCEPT
  - iptables:
      chain: FORWARD
      match: conntrack
      ctstate: ["RELATED","ESTABLISHED"]
      jump: ACCEPT
  - iptables:
      chain: FORWARD
      in_interface: wg0
      out_interface: wg0
      match: conntrack
      ctstate: ["NEW"]
      jump: ACCEPT
      
  - iptables:
      chain: FORWARD
      in_interface: wg0
      jump: ACCEPT
  - iptables:
      table: nat
      chain: POSTROUTING
      out_interface: ens2
      jump: MASQUERADE