--- - name: Create JWT identity directory ansible.builtin.file: path: "{{ openvpn_pki_jwt_directory }}" state: directory owner: root group: root mode: "0700" - name: Check for existing JWT private key ansible.builtin.stat: path: "{{ openvpn_pki_jwt_private_key_path }}" register: openvpn_pki_jwt_private_key_stat - name: Check for existing JWT public key ansible.builtin.stat: path: "{{ openvpn_pki_jwt_public_key_path }}" register: openvpn_pki_jwt_public_key_stat - name: Refuse incomplete JWT identity ansible.builtin.assert: that: - openvpn_pki_jwt_private_key_stat.stat.exists == openvpn_pki_jwt_public_key_stat.stat.exists fail_msg: >- Only one JWT key file exists. Refusing to replace or repair an existing identity automatically. Inspect the files and recover the matching key pair deliberately before rerunning this playbook. - name: Generate JWT RSA private key community.crypto.openssl_privatekey: path: "{{ openvpn_pki_jwt_private_key_path }}" type: RSA size: "{{ openvpn_pki_jwt_rsa_bits }}" owner: root group: root mode: "0600" when: not openvpn_pki_jwt_private_key_stat.stat.exists - name: Generate JWT public key from existing private key community.crypto.openssl_publickey: path: "{{ openvpn_pki_jwt_public_key_path }}" privatekey_path: "{{ openvpn_pki_jwt_private_key_path }}" format: PEM owner: root group: root mode: "0644" when: not openvpn_pki_jwt_public_key_stat.stat.exists - name: Create public key artifact directory on controller ansible.builtin.file: path: "{{ openvpn_pki_public_key_artifact_directory }}" state: directory mode: "0700" delegate_to: localhost become: false - name: Fetch JWT public key to controller ansible.builtin.fetch: src: "{{ openvpn_pki_jwt_public_key_path }}" dest: "{{ openvpn_pki_public_key_artifact_directory }}/{{ inventory_hostname }}.pem" flat: true validate_checksum: true