aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roles/wireguard/tasks/main.yml
blob: f48f8cb27dc35d7da54634b84aaa54e5fa5880d5 (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
- name: Set up Wireguard
  become: true
  block:
    - name: Install wireguard-tools
      ansible.builtin.package:
        name: wireguard-tools
        state: present

    - name: Write wg-quick config file
      ansible.builtin.template:
        src: wg0.conf.j2
        dest: '/etc/wireguard/{{ wg_name }}.conf'
        owner: root
        group: root
        mode: '600'
      register: config

    - name: Restart wg-quick service
      ansible.builtin.systemd_service:
        name: 'wg-quick@{{ wg_name }}'
        enabled: true
        state: restarted
      when: config.changed

- name: Set up service dependencies for the interface
  ansible.builtin.include_role:
    name: systemd_depend_iface
  vars:
    systemd_depend_iface_name: '{{ wg_name }}'
    systemd_depend_iface_services: '{{ wg_dependent_services }}'

- name: Create override directory for services
  become: true
  ansible.builtin.file:
    path: '/etc/systemd/system/{{ service }}.service.d'
    state: directory
    owner: root
    group: root
    mode: '755'
  loop: '{{ wg_dependent_services }}'
  loop_control:
    loop_var: service

- name: Set up service dependencies for wg-quick
  become: true
  ansible.builtin.template:
    src: depend_service_wg-quick.conf.j2
    dest: '/etc/systemd/system/{{ service }}.service.d/depend_service_wg-quick@{{ wg_name }}.conf'
    owner: root
    group: root
    mode: '644'
  notify: wireguard_reload
  loop: '{{ wg_dependent_services }}'
  loop_control:
    loop_var: service

- name: Reload systemd services if necessary
  ansible.builtin.meta: flush_handlers