ansible-roles/vpn/wireguard/tasks/main.yml

52 lines
1.5 KiB
YAML
Raw Normal View History

2022-12-20 19:47:11 +01:00
---
- name: "install wireguard"
ansible.builtin.apt:
name: "wireguard"
- name: "configure wireguard"
ansible.builtin.template:
src: "./{{ vpn_wireguard_role }}/IFACE.conf"
2023-07-20 20:27:37 +02:00
dest: "/etc/wireguard/{{ vpn_wireguard_iface }}.conf"
2022-12-20 19:47:11 +01:00
mode: 0600
register: vpn_wireguard_conf
- name: "post-up nftables inet script"
ansible.builtin.template:
2023-07-20 20:27:37 +02:00
src: "./post-up-IFACE-inet.nft"
dest: "/usr/local/sbin/post-up-{{ vpn_wireguard_iface }}-inet.nft"
2022-12-20 19:47:11 +01:00
mode: 0755
2023-07-20 20:27:37 +02:00
register: vpn_wireguard_post_up_iface_inet_nft
2022-12-20 19:47:11 +01:00
- name: "configure interface"
ansible.builtin.template:
src: "./{{ vpn_wireguard_role }}/IFACE"
2023-07-20 20:27:37 +02:00
dest: "/etc/network/interfaces.d/{{ vpn_wireguard_iface }}"
2022-12-20 19:47:11 +01:00
mode: 0644
validate: >
bash -c
2023-07-20 20:27:37 +02:00
'if ! diff %s /etc/network/interfaces.d/{{ vpn_wireguard_iface }} &&
ip link show dev {{ vpn_wireguard_iface }} ;
2022-12-20 19:47:11 +01:00
then
2023-07-20 20:27:37 +02:00
ifdown {{ vpn_wireguard_iface }} ;
2022-12-20 19:47:11 +01:00
fi'
register: vpn_wireguard_intf
- name: "restart interface"
ansible.builtin.shell: |
2023-07-20 20:27:37 +02:00
if ip link show dev {{ vpn_wireguard_iface }}
2022-12-20 19:47:11 +01:00
then
2023-07-20 20:27:37 +02:00
ifdown {{ vpn_wireguard_iface }} && ifup {{ vpn_wireguard_iface }}
2022-12-20 19:47:11 +01:00
else
2023-07-20 20:27:37 +02:00
ifup {{ vpn_wireguard_iface }}
2022-12-20 19:47:11 +01:00
fi
when:
vpn_wireguard_conf.changed or
2023-07-20 20:27:37 +02:00
vpn_wireguard_post_up_iface_inet_nft.changed or
2022-12-20 19:47:11 +01:00
vpn_wireguard_intf.changed
- name: "pre-down nftables inet script"
2023-07-20 20:27:37 +02:00
ansible.builtin.template:
src: "./pre-down-IFACE-inet.nft"
dest: "/usr/local/sbin/pre-down-{{ vpn_wireguard_iface }}-inet.nft"
2022-12-20 19:47:11 +01:00
mode: 0755