user2211579
user2211579

Reputation: 51

Ansible permission problems

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....

Picture Here with errors

Upvotes: 4

Views: 8967

Answers (1)

mvk_il
mvk_il

Reputation: 960

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:

  • Determine which ssh methodology you want/need to use here - ssh-agent, or passwordless default ssh key, b/c the 1st command failed due to key problem. you also can pass parameter --private-key=/path/to/key, if it is passwordless.
  • Fix: As user root make ALL files under /home/chris belong to user chris and its default group: sudo chown -R chris:chris /home/chris
  • if you have a lot of data the above command may take some time
  • run your playbooks from the specific, same user, and don't mix. if you're mixing - learn how to do it properly.
  • learn/read/experiment about unix permissions, identity switching, environment, etc., b/c this is not a case of "ansible permissions" problem, but "chris understanding unix permissions" problem, which is OK, given you're just beginning with unix/linux

Good luck.

Upvotes: 4

Related Questions