I have seen this a lot on this forum but none of the answers have helped me.
I am trying to run an ansible playbook, this worked fine on my Debian PC. Now I have moved to Ubuntu 16.04 it's not working. I get permission denied public key errors.
I am assuming this is because I am running sudo ansible-playbook.
This would then try to use the public key from my root user which is not on the servers I am trying to ansible.
How do I run an ansible-playbook as sudo but use the ssh keys from my current user?
If I run as sudo I get
fatal: [10.11.8.1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey).\r\n", "unreachable": true}
If I don't run as sudo I get
fatal: [10.11.8.1]: FAILED! => {"failed": true, "msg": "Cannot write to ControlPath /home/chrisl/.ansible/cp"}
[WARNING]: Could not create retry file '/home/chrisl/ansible/keys.retry'. [Errno 13] Permission denied: u'/home/chrisl/ansible/keys.retry'
I have also tried this and you can see what happens....

AFTER you ran the 1st command ansible-playbook as user root, from your user chris, that execution left (create) files that belong to the user root under the home folder of chris. Then next run as user chris fails to modify files that belong to root.
What you should do is:
--private-key=/path/to/key, if it is passwordless.root make ALL files under /home/chris belong to user chris and its default group: sudo chown -R chris:chris /home/chrisGood luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With