aboutsummaryrefslogtreecommitdiffstats
path: root/roles/wireguard/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'roles/wireguard/tasks')
-rw-r--r--roles/wireguard/tasks/generate.yml54
-rw-r--r--roles/wireguard/tasks/main.yml41
-rw-r--r--roles/wireguard/tasks/set_facts.yml6
3 files changed, 26 insertions, 75 deletions
diff --git a/roles/wireguard/tasks/generate.yml b/roles/wireguard/tasks/generate.yml
deleted file mode 100644
index 6e60a92..0000000
--- a/roles/wireguard/tasks/generate.yml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-# wireguard ~~ tasks/generate.yml
-
-- stat:
- path: "{{ wg_host_keys }}"
- register: stat_host_keys
- delegate_to: localhost
-
-- name: Generate domain keys
- shell: |
- umask 077
- wg genkey | tee "{{ wg_host_keys }}" | wg pubkey >> "{{ wg_host_keys }}"
- args:
- chdir: "{{ wg_dir }}"
- when: not stat_host_keys.stat.exists or force is defined and force
- delegate_to: localhost
-
-- name: Create wireguard dir on remote host
- file:
- path: /etc/wireguard
- owner: root
- state: directory
- mode: "0700"
- ignore_unreachable: true
-
-- name: Generate client configuration
- template:
- src: templates/host.conf.j2
- dest: "{{ item.path }}"
- mode: "0600"
- when: ansible_host != _i.dcontroller
- delegate_to: "{{ item.name }}"
- loop:
- - { name: "{{ ansible_host }}", path: /etc/wireguard/dcontroller.conf }
- - { name: localhost, path: "{{ wg_dir }}/{{ ansible_host}}.conf" }
- ignore_unreachable: true
-
-- name: Generate server configuration
- template:
- src: templates/dcontroller.conf.j2
- dest: "{{ item.path }}"
- mode: "0600"
- when: ansible_host == _i.dcontroller
- delegate_to: "{{ item.name }}"
- loop:
- - { name: "{{ ansible_host }}", path: /etc/wireguard/dcontroller.conf }
- - { name: localhost, path: "{{ wg_dir }}/{{ ansible_host}}.conf" }
-
-- name: Generate server interface
- template:
- src: templates/hostname.j2
- dest: /etc/hostname.tun0
- when: ansible_host == _i.dcontroller
-
diff --git a/roles/wireguard/tasks/main.yml b/roles/wireguard/tasks/main.yml
index 9e23fa7..51b97c0 100644
--- a/roles/wireguard/tasks/main.yml
+++ b/roles/wireguard/tasks/main.yml
@@ -1,15 +1,19 @@
-# wireguard ~~ tasks/main.yml
+
+# wireguard ~~ roles/wireguard/tasks/main.yml
+# create keys and configuration for wireguard hosts
---
-- include: set_facts.yml
+- name: generate dynamic facts
+ include: set_facts.yml
-- stat:
+- name: check keys on local disk
+ stat:
path: "{{ wg_host_keys }}"
register: stat_host_keys
delegate_to: localhost
-- name: Generate domain keys
+- name: generate host keys
shell: |
umask 077
wg genkey | tee "{{ wg_host_keys }}" | wg pubkey >> "{{ wg_host_keys }}"
@@ -18,40 +22,41 @@
when: not stat_host_keys.stat.exists or force is defined and force
delegate_to: localhost
-- name: Create wireguard dir on remote host
+- name: create wireguard dir on remote host
file:
path: /etc/wireguard
- owner: root
+ owner: "{{ user_root }}"
+ group: "{{ group_root }}"
+ mode: 0700
state: directory
- mode: "0700"
ignore_unreachable: true
-- name: Generate client configuration
+- name: generate client configuration
template:
- src: templates/host.conf.j2
+ src: host.conf.j2
dest: "{{ item.path }}"
- mode: "0600"
- when: ansible_host != _i.dcontroller
+ mode: 0600
+ when: ansible_host != global.dcontroller
delegate_to: "{{ item.name }}"
loop:
- { name: "{{ ansible_host }}", path: /etc/wireguard/dcontroller.conf }
- - { name: localhost, path: "{{ wg_dir }}/{{ ansible_host}}.conf" }
+ - { name: localhost, path: "{{ wg_dir }}/{{ ansible_host }}.conf" }
ignore_unreachable: true
-- name: Generate server configuration
+- name: generate server configuration
template:
- src: templates/dcontroller.conf.j2
+ src: dcontroller.conf.j2
dest: "{{ item.path }}"
mode: "0600"
- when: ansible_host == _i.dcontroller
+ when: ansible_host == global.dcontroller
delegate_to: "{{ item.name }}"
loop:
- { name: "{{ ansible_host }}", path: /etc/wireguard/dcontroller.conf }
- - { name: localhost, path: "{{ wg_dir }}/{{ ansible_host}}.conf" }
+ - { name: localhost, path: "{{ wg_dir }}/{{ ansible_host }}.conf" }
-- name: Generate server interface
+- name: generate server interface
template:
src: templates/hostname.j2
dest: /etc/hostname.tun0
- when: ansible_host == _i.dcontroller
+ when: ansible_host == global.dcontroller
diff --git a/roles/wireguard/tasks/set_facts.yml b/roles/wireguard/tasks/set_facts.yml
index 933ca9d..7e042ea 100644
--- a/roles/wireguard/tasks/set_facts.yml
+++ b/roles/wireguard/tasks/set_facts.yml
@@ -4,10 +4,10 @@
---
- set_fact:
- wg_dir: "{{ inventory_dir}}/files/wireguard"
+ wg_dir: "{{ inventory_dir }}/files/wireguard"
- set_fact:
- wg_dcontroller_conf: "{{ wg_dir }}/{{ _i.dcontroller }}.conf"
- wg_dcontroller_keys: "{{ wg_dir }}/{{ _i.dcontroller }}.keys"
+ wg_dcontroller_conf: "{{ wg_dir }}/{{ global.dcontroller }}.conf"
+ wg_dcontroller_keys: "{{ wg_dir }}/{{ global.dcontroller }}.keys"
wg_host_conf: "{{ wg_dir }}/{{ ansible_host }}.conf"
wg_host_keys: "{{ wg_dir }}/{{ ansible_host }}.keys"
remember that computers suck.