|
|
@ -1,43 +1,41 @@
|
|
|
|
---
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Check for debian major version
|
|
|
|
|
|
|
|
assert:
|
|
|
|
|
|
|
|
that: "ansible_distribution_major_version is version_compare('10', '>=')"
|
|
|
|
|
|
|
|
msg: "This role requires at least Debian Buster"
|
|
|
|
|
|
|
|
|
|
|
|
- name: Install wireguard using apt
|
|
|
|
- name: Install wireguard using apt
|
|
|
|
apt:
|
|
|
|
apt:
|
|
|
|
name:
|
|
|
|
name:
|
|
|
|
- wireguard
|
|
|
|
- wireguard
|
|
|
|
state: present
|
|
|
|
state: present
|
|
|
|
|
|
|
|
|
|
|
|
- name: Create wireguard configuration environment directories
|
|
|
|
- name: Upgrade systemd to backports (required for buster)
|
|
|
|
|
|
|
|
apt:
|
|
|
|
|
|
|
|
default_release: buster-backports
|
|
|
|
|
|
|
|
name:
|
|
|
|
|
|
|
|
- libpam-systemd
|
|
|
|
|
|
|
|
- libsystemd0
|
|
|
|
|
|
|
|
- systemd
|
|
|
|
|
|
|
|
state: latest # required to trigger update
|
|
|
|
|
|
|
|
when: "ansible_distribution_major_version == '10'"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Create wireguard configuration directory
|
|
|
|
file:
|
|
|
|
file:
|
|
|
|
state: directory
|
|
|
|
state: directory
|
|
|
|
path: "{{ item }}"
|
|
|
|
path: "{{ global_wireguard_configuration_directory }}"
|
|
|
|
owner: root
|
|
|
|
|
|
|
|
group: root
|
|
|
|
|
|
|
|
mode: "u=rwx,g=rx,o=rx"
|
|
|
|
|
|
|
|
loop:
|
|
|
|
|
|
|
|
- "{{ global_wireguard_configuration_environment_directory }}"
|
|
|
|
|
|
|
|
- "{{ global_wireguard_configuration_environment_directory }}/peers"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Upload makefile to wireguard configuration environment
|
|
|
|
|
|
|
|
template:
|
|
|
|
|
|
|
|
src: wireguard.makefile
|
|
|
|
|
|
|
|
dest: "{{ global_wireguard_configuration_environment_directory }}/makefile"
|
|
|
|
|
|
|
|
owner: root
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
group: "{{ global_systemd_network_system_user }}"
|
|
|
|
mode: "u=rw,g=r,o=r"
|
|
|
|
mode: u=rwx,g=rx,o=rx
|
|
|
|
|
|
|
|
|
|
|
|
- name: Create link in ssh configuration environment
|
|
|
|
|
|
|
|
file:
|
|
|
|
|
|
|
|
state: link
|
|
|
|
|
|
|
|
src: "{{ global_wireguard_configuration_directory }}"
|
|
|
|
|
|
|
|
dest: "{{ global_wireguard_configuration_link }}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Create wireguard key directory
|
|
|
|
- name: Create wireguard key directory
|
|
|
|
file:
|
|
|
|
file:
|
|
|
|
state: directory
|
|
|
|
state: directory
|
|
|
|
path: "{{ wireguard_key_directory }}"
|
|
|
|
path: "{{ wireguard_key_directory }}"
|
|
|
|
owner: root
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
group: "{{ global_systemd_network_system_user }}"
|
|
|
|
mode: "u=rwx,g=,o="
|
|
|
|
mode: u=rwx,g=rx,o=
|
|
|
|
|
|
|
|
|
|
|
|
- name: Generate key pair
|
|
|
|
- name: Generate key pair
|
|
|
|
shell: >-
|
|
|
|
shell: >-
|
|
|
@ -48,6 +46,14 @@
|
|
|
|
chdir: "{{ wireguard_key_directory }}"
|
|
|
|
chdir: "{{ wireguard_key_directory }}"
|
|
|
|
creates: "{{ wireguard_public_key }}"
|
|
|
|
creates: "{{ wireguard_public_key }}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Secure key to prevent logging
|
|
|
|
|
|
|
|
file:
|
|
|
|
|
|
|
|
state: file
|
|
|
|
|
|
|
|
path: "{{ wireguard_private_key }}"
|
|
|
|
|
|
|
|
owner: root
|
|
|
|
|
|
|
|
group: "{{ global_systemd_network_system_user }}"
|
|
|
|
|
|
|
|
mode: u=rwx,g=rx,o=
|
|
|
|
|
|
|
|
|
|
|
|
- name: Download wireguard public key
|
|
|
|
- name: Download wireguard public key
|
|
|
|
fetch:
|
|
|
|
fetch:
|
|
|
|
src: "{{ wireguard_public_key }}"
|
|
|
|
src: "{{ wireguard_public_key }}"
|
|
|
@ -58,43 +64,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
- name: Store peer configuration locally
|
|
|
|
- name: Store peer configuration locally
|
|
|
|
template:
|
|
|
|
template:
|
|
|
|
src: "peer.cfg"
|
|
|
|
src: peer.conf
|
|
|
|
dest: "{{ global_wireguard_peers_directory }}/{{ inventory_hostname }}"
|
|
|
|
dest: "{{ global_wireguard_peers_directory }}/{{ inventory_hostname }}"
|
|
|
|
owner: "{{ local_user }}"
|
|
|
|
owner: "{{ local_user }}"
|
|
|
|
group: "{{ local_user }}"
|
|
|
|
group: "{{ local_user }}"
|
|
|
|
mode: "u=rw,g=r,o="
|
|
|
|
mode: "u=rw,g=r,o="
|
|
|
|
delegate_to: localhost
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
|
|
|
|
- name: Store main config
|
|
|
|
- name: Configure systemd for WireGuard
|
|
|
|
template:
|
|
|
|
|
|
|
|
src: "wireguard.cfg"
|
|
|
|
|
|
|
|
dest: "{{ global_wireguard_configuration_environment_directory }}/main.cfg"
|
|
|
|
|
|
|
|
owner: root
|
|
|
|
|
|
|
|
group: root
|
|
|
|
|
|
|
|
mode: "u=rw,g=,o="
|
|
|
|
|
|
|
|
notify:
|
|
|
|
|
|
|
|
- reassemble wireguard config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Add control scripts
|
|
|
|
|
|
|
|
template:
|
|
|
|
template:
|
|
|
|
src: "{{ item }}.sh"
|
|
|
|
src: "{{ item.src }}"
|
|
|
|
dest: "{{ global_wireguard_configuration_directory }}/{{ item }}.sh"
|
|
|
|
dest: "{{ item.dest }}"
|
|
|
|
owner: root
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
group: "{{ global_systemd_network_system_user }}"
|
|
|
|
mode: "u=rwx,g=r,o=r"
|
|
|
|
mode: u=rw,g=r,o=
|
|
|
|
validate: "{{ global_validate_shell_script }}"
|
|
|
|
|
|
|
|
notify:
|
|
|
|
|
|
|
|
- reload wireguard interface
|
|
|
|
|
|
|
|
loop:
|
|
|
|
loop:
|
|
|
|
- up
|
|
|
|
- src: wg.netdev
|
|
|
|
- down
|
|
|
|
dest: "{{ netdev_file }}"
|
|
|
|
|
|
|
|
- src: wg.network
|
|
|
|
|
|
|
|
dest: "{{ network_file }}"
|
|
|
|
|
|
|
|
notify:
|
|
|
|
|
|
|
|
- restart systemd network
|
|
|
|
|
|
|
|
|
|
|
|
- name: Configure WireGuard on boot
|
|
|
|
- name: Create directory for systemd WireGuard network
|
|
|
|
template:
|
|
|
|
file:
|
|
|
|
src: wireguard.service
|
|
|
|
state: directory
|
|
|
|
dest: "{{ global_systemd_configuration_directory }}/wireguard.service"
|
|
|
|
path: "{{ netdev_directory }}"
|
|
|
|
owner: root
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
group: "{{ global_systemd_network_system_user }}"
|
|
|
|
mode: "u=rw,g=r,o=r"
|
|
|
|
mode: u=rwx,g=rx,o=
|
|
|
|
notify:
|
|
|
|
|
|
|
|
- reload systemd
|
|
|
|
|
|
|
|