--- - name: Find a public SSH key file find: path: ~/.ssh/ pattern: id_*.pub register: ssh_key_result failed_when: ssh_key_result.matched < 1 - name: Set SSH public key fact set_fact: ssh_key_file: "{{ ssh_key_result.files[0].path }}"