Start a wireguard role.

This commit is contained in:
Tom Alexander 2022-12-03 17:16:37 -05:00
parent c55f5d735d
commit 83f8b2509b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
9 changed files with 156 additions and 31 deletions

1
.gitattributes vendored
View File

@ -1 +1,2 @@
cargo_credentials.toml filter=git-crypt diff=git-crypt cargo_credentials.toml filter=git-crypt diff=git-crypt
wireguard_configs/ filter=git-crypt diff=git-crypt

View File

@ -2,37 +2,38 @@
vars: vars:
ansible_become: True ansible_become: True
roles: roles:
- sudo # - sudo
- users # - users
- package_manager # - package_manager
- zrepl # - zrepl
- zsh # - zsh
- network # - network
- sshd # - sshd
- base # - base
- firewall # - firewall
- cpu # - cpu
- ntp # - ntp
- build # - build
- graphics # - graphics
- gpg # - gpg
- fonts # - fonts
- alacritty # - alacritty
- sway # - sway
- emacs # - emacs
- firefox # - firefox
- devfs # - devfs
- ssh_client # - ssh_client
- sshfs # - sshfs
- jail # - jail
- fuse # - fuse
- autofs # - autofs
- exfat # - exfat
- bhyve # - bhyve
- media # - media
- kubernetes # - kubernetes
- google_cloud_sdk # - google_cloud_sdk
- ansible # - ansible
- wireguard
- hosts: nat_dhcp:homeserver_nat_dhcp - hosts: nat_dhcp:homeserver_nat_dhcp
vars: vars:

View 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

View 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

View 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 }}"

View File

@ -0,0 +1,2 @@
- import_tasks: tasks/common.yaml
when: wireguard_directory is defined

View 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"'