aboutsummaryrefslogtreecommitdiffstats
path: root/roles/wireguard/tasks/server.yml
blob: 32d52fc5b157b9a8bacf08358e449e2fde005a07 (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

# wireguard ~~ roles/wireguard/tasks/main.yml
# create keys and configuration for wireguard hosts

---

- name: generate server configuration
  template:
    src: dcontroller.conf.j2
    dest: "{{ wg_dir }}/{{ ansible_host }}.conf"
    mode: "0600"
  when: ansible_host == global.dcontroller
  delegate_to: localhost

- name: generate server interface
  template:
    src: templates/hostname.j2
    dest: /etc/hostname.tun0

# NOTE: interface destruction and creation exists in the same tasks,
# to avoid being kicked out of the ssh sessions if this one exists
# within the current VPN.
- name: restart wireguard interface
  shell: |
    ifconfig tun0 destroy
    sleep 2
    sh /etc/netstart tun0
  register: result

- name: show debug output
  debug:
    msg: |
      {% for line in result.stdout_lines %}
      "{{ line }}"
      {% endfor %}
      {% for line in result.stderr_lines %}
      "{{ line }}"
      {% endfor %}
remember that computers suck.