From b232b894c3cbe087c8d504e91637dcf62199eed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Thu, 29 Jul 2021 17:00:20 +0200 Subject: Bump to third revision of homelab --- roles/wireguard/tasks/main.yml | 29 ++++------------------------- roles/wireguard/tasks/server.yml | 28 +++++++--------------------- roles/wireguard/tasks/service.yml | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 46 deletions(-) create mode 100644 roles/wireguard/tasks/service.yml (limited to 'roles/wireguard/tasks') diff --git a/roles/wireguard/tasks/main.yml b/roles/wireguard/tasks/main.yml index 5b48998..3b8f8ae 100644 --- a/roles/wireguard/tasks/main.yml +++ b/roles/wireguard/tasks/main.yml @@ -15,35 +15,14 @@ wg_host_conf: "{{ wg_dir }}/{{ ansible_host }}.conf" wg_host_keys: "{{ wg_dir }}/{{ ansible_host }}.keys" -- name: include configuration generation +- name: include generation configuratin include_tasks: generate.yml -- name: include configuration synchronization +- name: include synchronization configuration include_tasks: synchronize.yml -- name: enable wireguard for freebsd - lineinfile: - path: /etc/rc.conf - regexp: "^wireguard_enable" - line: wireguard_enable="YES" - when: ansible_distribution == "FreeBSD" - -- name: enable interface for freebsd - lineinfile: - path: /etc/rc.conf - regexp: "^wireguard_interfaces" - line: wireguard_interfaces="{{ global.dcontroller }}" - when: ansible_distribution == "FreeBSd" - -- name: generate and enable init script - include_role: name=rc - vars: - rc_cmd: "{{ path_wgquick }}" - rc_args: "up {{ global.dcontroller }}" - rc_name: wireguard - rc_user: "{{ user_root }}" - ignore_errors: true - when: ansible_distribution != "FreeBSD" +- name: include service configuration + include_tasks: service.yml - name: include server setup include_tasks: server.yml diff --git a/roles/wireguard/tasks/server.yml b/roles/wireguard/tasks/server.yml index 32d52fc..9a8d67c 100644 --- a/roles/wireguard/tasks/server.yml +++ b/roles/wireguard/tasks/server.yml @@ -12,27 +12,13 @@ when: ansible_host == global.dcontroller delegate_to: localhost -- name: generate server interface - template: - src: templates/hostname.j2 - dest: /etc/hostname.tun0 +- name: enable wireguard interface + lineinfile: + path: /etc/rc.local + regexp: "^wg-quick up {{ ansible_host }}$" + line: "wg-quick up {{ ansible_host }}" -# 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 %} + wg-quick down "{{ ansible_host }}" + wg-quick up "{{ ansible_host }}" diff --git a/roles/wireguard/tasks/service.yml b/roles/wireguard/tasks/service.yml new file mode 100644 index 0000000..86d6420 --- /dev/null +++ b/roles/wireguard/tasks/service.yml @@ -0,0 +1,17 @@ +- name: enable wireguard for FreeBSD + service: + name: wireguard + state: restarted + enabled: true + args: "{{ global.dcontroller }}" + when: ansible_distribution == "FreeBSD" + +- name: generate and enable init script + include_role: name=rc + vars: + rc_cmd: "{{ path_wgquick }}" + rc_args: "up {{ global.dcontroller }}" + rc_name: wireguard + rc_user: "{{ user_root }}" + ignore_errors: true + when: ansible_distribution != "FreeBSD" -- cgit v1.2.3