- name: Acquiring home of current user when: ansible_facts["system"] == "Linux" ansible.builtin.shell: cmd: "echo ~{{ ansible_user }}" register: ansible_user_home - name: Acquiring current user when: ansible_facts["system"] == "Linux" ansible.builtin.shell: cmd: "echo {{ ansible_user }}" register: current_user - name: Checking if ZFS filesystem is present ansible.builtin.shell: cmd: "findmnt -D | awk '{ print $2 }' | tail -n +2" register: fs_result - name: Logging presence of ZFS filesystem when: "'zfs' in fs_result.stdout" ansible.builtin.set_fact: zfs_present: true - name: Logging absence of ZFS filesystem when: "'zfs' not in fs_result.stdout" ansible.builtin.set_fact: zfs_present: false - name: Configuring ZFS support when: zfs_present block: - name: Getting available pools ansible.builtin.shell: cmd: "zpool list | awk '{ print $1 }' | tail -n +2" register: zpools - name: Turning available pools into list ansible.builtin.set_fact: zpool_list: "{{ zpools | replace('\n', ' ') | split(' ') }}" - name: Allowing choice of zpool ansible.builtin.pause: prompt: "Type preferred zpool from available (i.e., {{ zpool_list | join(', ') }})" register: preferred_zpool - name: Initializing DSNet become: true ansible.builtin.command: cmd: dsnet init - name: Running DSNet VPN service interface become: true ansible.builtin.command: cmd: dsnet up - name: Creating a ZFS dataset for DSNet configuration when: zfs_present become: true community.general.zfs: name: "{{ preferred_zpool.user_input }}/wireguard_clients" state: present extra_zfs_properties: canmount: "on" mountpoint: "{{ ansible_user_home.stdout }}/.wg" - name: Creating a directory to house VPN service client configurations become: true ansible.builtin.file: path: "{{ ansible_user_home.stdout }}/.wg" recurse: true owner: "{{ ansible_user }}" group: "{{ ansible_user }}" mode: "700" state: directory - name: Creating a directory to house VPN service client configurations ansible.builtin.file: path: "{{ ansible_user_home.stdout }}/.wg/authorized_clients.d" recurse: true owner: "{{ ansible_user }}" group: "{{ ansible_user }}" mode: "700" state: directory - name: Adding peer device for DSNet VPN service interface become: true when: "((fqdn is defined and fqdn != None) and fqdn in item.name) or (item.name in groups.homeserver or item.name in groups['homeserver.test'])" ansible.builtin.shell: cmd: "dsnet add {{ item.name }}{{ idx }} --owner {{ current_user.stdout }} --description 'For {{ item.name }}--{{ item.desc }}' --confirm > {{ ansible_user_home.stdout }}/.wg/authorized_clients.d/{{ item.name }}{{ (idx | string) }}.conf" creates: "{{ ansible_user_home.stdout }}/.wg/authorized_clients.d/{{ item.name }}{{ idx }}.conf" loop: "{{ vpn.clients }}" loop_control: index_var: idx - name: Changing ownership of consequent DSNet VPN service client configurations when: "((fqdn is defined and fqdn != None) and fqdn in item.name) or (item.name in groups.homeserver or item.name in groups['homeserver.test'])" ansible.builtin.file: path: "{{ ansible_user_home.stdout }}/.wg/authorized_clients.d/{{ item.name }}{{ (idx | string) }}.conf" owner: "{{ ansible_user }}" group: "{{ ansible_user }}" mode: "600" state: file loop: "{{ vpn.clients }}" loop_control: index_var: idx - name: Acquiring VPN server subnet block: - name: Acquiring VPN server IPv4 subnet ansible.builtin.shell: cmd: echo "$(" owner: root group: root mode: "755" force: true backup: true - name: Copying script for DSNet iptables rules become: true when: not ipv6_enabled ansible.builtin.template: src: usr/local/bin/dsnet-routing.sh.j2 dest: /usr/local/bin/dsnet-routing.sh variable_start_string: "<%" variable_end_string: "%>" owner: root group: root mode: "755" force: true backup: true - name: Creating SystemD unit for DSNet iptables rules become: true ansible.builtin.copy: src: systemd/system/thrunet.service dest: /etc/systemd/system/thrunet.service owner: root group: root force: true backup: true - name: Reloading SystemD become: true ansible.builtin.systemd_service: scope: system daemon_reload: true