- name: Update nginx stream configuration hosts: - colors - kubernetes - managed become: true become_user: root become_method: sudo tasks: - name: Ensure wireguard directory exists ansible.builtin.file: path: /etc/wireguard state: directory mode: '0700' - name: Check if privatekey exists stat: path=/etc/wireguard/privatekey register: key - name: Generate pubkey and privatekey shell: wg genkey | tee /etc/wireguard/privatekey | wg pubkey > /etc/wireguard/publickey when: not key.stat.exists or key.stat.size == 0 - name: cat pubkey command: cat /etc/wireguard/publickey register: pubkey - name: Print publickey to console debug: msg: "{{pubkey.stdout}}"