mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
Add simple Wireguard playbook. Add Ansible configuration. Add README.md with instructions. Signed-off-by: Scott Lowe <scott.lowe@scottlowe.org>
56 lines
1.4 KiB
YAML
56 lines
1.4 KiB
YAML
---
|
|
- hosts: "all"
|
|
gather_facts: true
|
|
become: true
|
|
|
|
tasks:
|
|
- name: "Install Wireguard"
|
|
apt:
|
|
name:
|
|
- "wireguard"
|
|
- "wireguard-tools"
|
|
state: "present"
|
|
when: ansible_distribution == "Ubuntu"
|
|
|
|
- name: "Enable IP forwarding"
|
|
sysctl:
|
|
name: "net.ipv4.ip_forward"
|
|
value: '1'
|
|
sysctl_set: yes
|
|
state: "present"
|
|
reload: yes
|
|
|
|
- name: "Check if Wireguard configuration directory exists"
|
|
stat:
|
|
path: "/etc/wireguard"
|
|
register: wg_conf_directory
|
|
|
|
- name: "Create Wireguard configuration directory"
|
|
file:
|
|
path: "/etc/wireguard"
|
|
owner: "root"
|
|
group: "root"
|
|
mode: 0700
|
|
when: not wg_conf_directory.stat.exists
|
|
|
|
- name: "Check if Wireguard private key exists"
|
|
stat:
|
|
path: "/etc/wireguard/privatekey"
|
|
register: wg_private_key
|
|
|
|
- name: "Generate private key if it doesn't exist"
|
|
command: "wg genkey"
|
|
register: wg_generate_private_key
|
|
when: not wg_private_key.stat.exists
|
|
|
|
- name: "Check if Wireguard public key exists"
|
|
stat:
|
|
path: "/etc/wireguard/publickey"
|
|
register: wg_public_key
|
|
|
|
- name: "Generate public key if it doesn't exist"
|
|
command: "wg pubkey"
|
|
args:
|
|
stdin: "{{ wg_generate_private_key.stdout }}"
|
|
register: wg_generate_public_key
|
|
when: not wg_public_key.stat.exists
|