summaryrefslogtreecommitdiff
path: root/roles/network/wireguard/gateway/tasks/main.yml
blob: bc14db1b1afa2e7840e0de85342d6432c4c7c23f (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
---
- name: install wireguard interfaces (netdev)
  loop: "{{ wireguard_gateway_tunnels | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  template:
    src: systemd.netdev.j2
    dest: "/etc/systemd/network/{{ item.key }}.netdev"
    mode: 0640
    group: systemd-network
  notify: restart systemd-networkd

- name: install wireguard interfaces (network)
  loop: "{{ wireguard_gateway_tunnels | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  template:
    src: systemd.network.j2
    dest: "/etc/systemd/network/{{ item.key }}.network"
  notify: restart systemd-networkd

- name: enable systemd-networkd
  systemd:
    name: systemd-networkd
    enabled: yes
    state: started


- name: create iptables service unit
  loop: "{{ wireguard_gateway_tunnels | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  when: "'ip_snat' in item.value or 'port_forwardings' in item.value"
  template:
    src: systemd-iptables.service.j2
    dest: "/etc/systemd/system/wireguard-gateway-{{ item.key }}-iptables.service"

- name: enable/start iptables service unit
  loop: "{{ wireguard_gateway_tunnels | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  when: "'ip_snat' in item.value or 'port_forwardings' in item.value"
  systemd:
    daemon_reload: yes
    name: "wireguard-gateway-{{ item.key }}-iptables.service"
    enabled: yes
    state: started


- name: install workaround for default-gateway handling
  loop: "{{ wireguard_gateway_tunnels | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  when: "'default_gateway' in item.value"
  template:
    src: systemd-fix-default-gw.service.j2
    dest: "/etc/systemd/system/wireguard-gateway-{{ item.key }}-fix-default-gw.service"

- name: enable/start workaround for default-gateway handling
  loop: "{{ wireguard_gateway_tunnels | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  when: "'default_gateway' in item.value"
  systemd:
    daemon_reload: yes
    name: "wireguard-gateway-{{ item.key }}-fix-default-gw.service"
    enabled: yes
    state: started