Start a wireguard role.
This commit is contained in:
15
ansible/roles/wireguard/tasks/common.yaml
Normal file
15
ansible/roles/wireguard/tasks/common.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
- import_tasks: tasks/freebsd.yaml
|
||||
when: 'os_flavor == "freebsd"'
|
||||
|
||||
- import_tasks: tasks/linux.yaml
|
||||
when: 'os_flavor == "linux"'
|
||||
|
||||
- include_tasks:
|
||||
file: tasks/peruser.yaml
|
||||
apply:
|
||||
become: yes
|
||||
become_user: "{{ initialize_user }}"
|
||||
when: users is defined
|
||||
loop: "{{ users | dict2items | community.general.json_query('[?value.initialize==`true`].key') }}"
|
||||
loop_control:
|
||||
loop_var: initialize_user
|
||||
53
ansible/roles/wireguard/tasks/freebsd.yaml
Normal file
53
ansible/roles/wireguard/tasks/freebsd.yaml
Normal file
@@ -0,0 +1,53 @@
|
||||
- name: Install packages
|
||||
package:
|
||||
name:
|
||||
- wireguard
|
||||
state: present
|
||||
|
||||
- name: Configure wireguard
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: /usr/local/etc/wireguard/
|
||||
mode: 0440
|
||||
owner: root
|
||||
group: root
|
||||
with_fileglob: "files/wireguard_configs/{{ wireguard_directory }}/*.conf"
|
||||
|
||||
- name: Enable Wireguard
|
||||
when: enabled_wireguard is defined
|
||||
systemd:
|
||||
enabled: yes
|
||||
name: "wg-quick@{{ item }}"
|
||||
daemon_reload: yes
|
||||
loop: "{{ enabled_wireguard }}"
|
||||
|
||||
- name: Enable gateway
|
||||
when: wireguard_gateway is defined and wireguard_gateway == true
|
||||
community.general.sysrc:
|
||||
name: "{{ item }}"
|
||||
value: "YES"
|
||||
path: /etc/rc.conf.d/routing
|
||||
loop:
|
||||
- gateway_enable
|
||||
- ipv6_gateway_enable
|
||||
|
||||
- name: Enable wireguard service
|
||||
when: enabled_wireguard is defined
|
||||
community.general.sysrc:
|
||||
name: wireguard_enable
|
||||
value: "YES"
|
||||
path: /etc/rc.conf.d/wireguard
|
||||
|
||||
- name: Disable wireguard service
|
||||
when: enabled_wireguard is not defined
|
||||
community.general.sysrc:
|
||||
name: wireguard_enable
|
||||
value: "NO"
|
||||
path: /etc/rc.conf.d/wireguard
|
||||
|
||||
- name: Set enabled wireguard list
|
||||
when: enabled_wireguard is defined
|
||||
community.general.sysrc:
|
||||
name: wireguard_interfaces
|
||||
value: "{{ enabled_wireguard|join(' ') }}"
|
||||
path: /etc/rc.conf.d/wireguard
|
||||
24
ansible/roles/wireguard/tasks/linux.yaml
Normal file
24
ansible/roles/wireguard/tasks/linux.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
- name: Install packages
|
||||
package:
|
||||
name:
|
||||
- wireguard-tools
|
||||
- qrencode # For generating qr codes to send to phone with `qrencode -t ansiutf8 -r <config_file>`
|
||||
- systemd-resolvconf # For wg-quick to regenerate resolv.conf
|
||||
state: present
|
||||
|
||||
- name: Configure wireguard
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: /etc/wireguard/
|
||||
mode: 0440
|
||||
owner: root
|
||||
group: root
|
||||
with_fileglob: "files/wireguard_configs/{{ wireguard_directory }}/*.conf"
|
||||
|
||||
- name: Enable Wireguard
|
||||
when: enabled_wireguard is defined
|
||||
systemd:
|
||||
enabled: yes
|
||||
name: "wg-quick@{{ item }}"
|
||||
daemon_reload: yes
|
||||
loop: "{{ enabled_wireguard }}"
|
||||
2
ansible/roles/wireguard/tasks/main.yaml
Normal file
2
ansible/roles/wireguard/tasks/main.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- import_tasks: tasks/common.yaml
|
||||
when: wireguard_directory is defined
|
||||
29
ansible/roles/wireguard/tasks/peruser.yaml
Normal file
29
ansible/roles/wireguard/tasks/peruser.yaml
Normal file
@@ -0,0 +1,29 @@
|
||||
- include_role:
|
||||
name: per_user
|
||||
|
||||
# - name: Create directories
|
||||
# file:
|
||||
# name: "{{ account_homedir.stdout }}/{{ item }}"
|
||||
# state: directory
|
||||
# mode: 0700
|
||||
# owner: "{{ account_name.stdout }}"
|
||||
# group: "{{ group_name.stdout }}"
|
||||
# loop:
|
||||
# - ".config/foo"
|
||||
|
||||
# - name: Copy files
|
||||
# copy:
|
||||
# src: "files/{{ item.src }}"
|
||||
# dest: "{{ account_homedir.stdout }}/{{ item.dest }}"
|
||||
# mode: 0600
|
||||
# owner: "{{ account_name.stdout }}"
|
||||
# group: "{{ group_name.stdout }}"
|
||||
# loop:
|
||||
# - src: foo.conf
|
||||
# dest: .config/foo/foo.conf
|
||||
|
||||
- import_tasks: tasks/peruser_freebsd.yaml
|
||||
when: 'os_flavor == "freebsd"'
|
||||
|
||||
- import_tasks: tasks/peruser_linux.yaml
|
||||
when: 'os_flavor == "linux"'
|
||||
0
ansible/roles/wireguard/tasks/peruser_freebsd.yaml
Normal file
0
ansible/roles/wireguard/tasks/peruser_freebsd.yaml
Normal file
0
ansible/roles/wireguard/tasks/peruser_linux.yaml
Normal file
0
ansible/roles/wireguard/tasks/peruser_linux.yaml
Normal file
Reference in New Issue
Block a user