diff --git a/tasks/deploy_wireguard.yml b/tasks/deploy_wireguard.yml index 70cfe84..5137005 100644 --- a/tasks/deploy_wireguard.yml +++ b/tasks/deploy_wireguard.yml @@ -107,4 +107,12 @@ wait_timeout: "{{ infra_compose_wait_timeout }}" register: deploy_wireguard_services_output +- name: Copy print-qr-codes util script into place + ansible.builtin.template: + src: print-qr-codes.sh.j2 + dest: "{{ infra_wireguard_directory_path }}/print-qr-codes.sh" + owner: "{{ infra_wireguard_directory_owner }}" + group: "{{ infra_wireguard_directory_group }}" + mode: "0750" + ... diff --git a/templates/print-qr-codes.sh.j2 b/templates/print-qr-codes.sh.j2 new file mode 100644 index 0000000..02d729c --- /dev/null +++ b/templates/print-qr-codes.sh.j2 @@ -0,0 +1,17 @@ +#! /usr/bin/env bash + +# util to print QR codes for wireguard configs +# requires 'jq' and 'qrencode' to be installed + +if ! command -v jq &> /dev/null; then + echo "Missing required package 'jq'" + exit 1 +elif ! command -v qrencode &> /dev/null; then + echo "Missing required package 'qrencode'" + exit 1 +fi + +for wgcfg in $(docker volume inspect {{ infra_wireguard_volume_name_config }} | jq '.[].Mountpoint' | sed 's/"//g')/peer_*/peer_*.conf; do + echo $(basename "$wgcfg") + qrencode -t ansiutf8 < "$wgcfg" +done