I’m sure it’s something I’m doing… but I managed to create a playbook to create my ansible user, add the SSH key, and all of that to a remote server.
However, to get it to run - I need to use the --ask-pass parameter.
ansible-playbook -i “remote_server,” add_ans_user.yml -b --ask-pass << That works and creates the user just fine, which makes sense as it needs to create the account as root.
After running the playbook to create the user, I can SSH without issues as the user to the remote server, no password required - which means it should be using the SSH key just fine.
The playbook adds the public key (key_file: “/opt/ansible_account/.ssh/id_rsa.pub”) - which seems to work for authentication for this account.
[ansible_account@remote_server linux_small_plays]$ ssh remote_server
Last login: Wed Apr 8 11:09:20 2020 from remote_server.domain.com
[ansible_account@remote_server ~]$
But when I attempt a ping with this account, it fails.
[ansible_account@ansible_controller linux_small_plays]$ ansible -m ping remote_server
Wednesday 08 April 2020 14:14:38 -0500 (0:00:00.077) 0:00:00.077 *******
remote_server | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).”,
“unreachable”: true
}
Wednesday 08 April 2020 14:14:39 -0500 (0:00:00.335) 0:00:00.413 *******