2023-10-01 17:02:49 +02:00
|
|
|
---
|
|
|
|
- name: Packages
|
|
|
|
ansible.builtin.include_tasks: install.yml
|
|
|
|
tags: install
|
|
|
|
|
2024-11-20 18:13:02 +01:00
|
|
|
- name: Check for existence of private key
|
|
|
|
ansible.builtin.stat:
|
|
|
|
path: /etc/wireguard/private.key
|
|
|
|
register: _private_key_stat
|
2023-10-01 17:02:49 +02:00
|
|
|
|
2024-11-20 18:13:02 +01:00
|
|
|
- name: Generate keypair
|
|
|
|
ansible.builtin.include_tasks: tasks/generate_keypair.yml
|
|
|
|
when: not _private_key_stat.exists
|
2023-10-01 17:02:49 +02:00
|
|
|
|
2024-11-20 18:13:02 +01:00
|
|
|
- name: Save private key
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: templates/keyfile.j2
|
|
|
|
dest: /etc/wireguard/private.key
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0700
|
|
|
|
vars:
|
|
|
|
key: "{{ wg_private_key }}"
|
|
|
|
when: not _private_key_stat.exists
|
2023-10-01 17:02:49 +02:00
|
|
|
|
2024-11-20 18:13:02 +01:00
|
|
|
- name: Save public key
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: templates/keyfile.j2
|
|
|
|
dest: /etc/wireguard/public.key
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0700
|
|
|
|
vars:
|
|
|
|
key: "{{ wg_public_key }}"
|
|
|
|
when: not _private_key_stat.exists
|
2023-10-01 17:02:49 +02:00
|
|
|
|
|
|
|
- name: Set dns_command for co-openSUSE
|
|
|
|
ansible.builtin.set_fact:
|
2024-07-12 19:53:09 +02:00
|
|
|
wg_dns_command: "resolvectl dns %i {{ wg_gateway }}; resolvectl domain %i ~{{ wg_domain }}"
|
2024-07-01 21:56:44 +02:00
|
|
|
when: '"openSUSE" not in ansible_distribution'
|
2023-10-01 17:02:49 +02:00
|
|
|
|
|
|
|
- name: Set dns_command for openSUSE
|
|
|
|
ansible.builtin.set_fact:
|
2024-07-12 19:53:09 +02:00
|
|
|
wg_dns_command: "nmcli con mod %i ipv4.dns {{ wg_gateway }}; nmcli con mod %i ipv4.dns-search ~{{ wg_domain }}"
|
2024-07-01 21:56:44 +02:00
|
|
|
when: '"openSUSE" in ansible_distribution'
|
2023-10-01 17:02:49 +02:00
|
|
|
|
|
|
|
- name: Create the config
|
|
|
|
vars:
|
2024-07-12 19:53:09 +02:00
|
|
|
address: "{{ wg_address }}"
|
2023-10-01 17:02:49 +02:00
|
|
|
dns_command: "{{ wg_dns_command }}"
|
2024-07-12 19:53:09 +02:00
|
|
|
domain: "{{ wg_domain }}"
|
|
|
|
gateway: "{{ wg_gateway }}"
|
|
|
|
peers: "{{ wg_peers }}"
|
2023-10-01 17:02:49 +02:00
|
|
|
ansible.builtin.template:
|
2024-07-15 15:44:30 +02:00
|
|
|
src: "templates/wg.conf"
|
2024-07-12 19:53:09 +02:00
|
|
|
dest: "/etc/wireguard/{{ wg_ifname }}.conf"
|
2023-10-01 17:02:49 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: "0600"
|
|
|
|
|
|
|
|
- name: Set up the DNS on AlmaLinux
|
|
|
|
ansible.builtin.include_tasks: "dns_{{ ansible_distribution }}.yml"
|
2024-07-15 15:44:30 +02:00
|
|
|
when: wg_domain and ansible_distribution == "AlmaLinux"
|
2023-10-01 17:02:49 +02:00
|
|
|
|
|
|
|
- name: Enable and start the wireguard connection
|
|
|
|
ansible.builtin.service:
|
2024-07-12 19:53:09 +02:00
|
|
|
name: "wg-quick@{{ wg_ifname }}"
|
2023-10-01 17:02:49 +02:00
|
|
|
enabled: yes
|
|
|
|
state: started
|