diff options
author | Romain Gonçalves <me@rgoncalves.se> | 2021-07-29 17:00:20 +0200 |
---|---|---|
committer | Romain Gonçalves <me@rgoncalves.se> | 2021-07-29 17:00:20 +0200 |
commit | b232b894c3cbe087c8d504e91637dcf62199eed1 (patch) | |
tree | ea72a7d1a7f63c6425ee46785e1cec924351b2c3 /roles/wireguard/tasks | |
parent | 22126073344e60c405d086df37b64da0c6d3c086 (diff) | |
download | infrastructure-b232b894c3cbe087c8d504e91637dcf62199eed1.tar.gz |
Bump to third revision of homelab
Diffstat (limited to 'roles/wireguard/tasks')
-rw-r--r-- | roles/wireguard/tasks/main.yml | 29 | ||||
-rw-r--r-- | roles/wireguard/tasks/server.yml | 28 | ||||
-rw-r--r-- | roles/wireguard/tasks/service.yml | 17 |
3 files changed, 28 insertions, 46 deletions
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" |