7
votes

I'm generated ssh key, and copy it to remote server. When I try to ssh to that server everything works fine:

ssh user@ip_address

User is not a root. If I try to ssh throw ansible:

ansible-playbook -i hosts playbook.yml

with ansible playbook:

---
- hosts: web
  remote_user: user
  tasks:
    - name: test connection
      ping:

and hosts file:

[web]
192.168.0.103

I got error:

...
Permission denied (publickey,password)

What's the problem?

3
when you say "everything works fine", does it ask for password or not? Rerun with -vvvv and post the output.. - Kashyap

3 Answers

9
votes

Ansible is using different key compared to what you are using to connect to that 'web' machine.

You can explicitly configure ansible to use a specific private key by

private_key_file=/path/to/key_rsa

as mentioned in the docs Make sure that you authorize that key which ansible uses, to the remote user in remote machine with ssh-copy-id -i /path/to/key_rsa.pub user@webmachine_ip_address

1
votes

In my case I got similar error while running ansible playbook when host changed it's fingerprint. I found this, trying to establish ssh connection from command line. So, after running ssh-keygen -f "/root/.ssh/known_hosts" -R my_ip this problem was solved.

0
votes

Hi Run the play as below. by default ansible plays using root. ansible-playbook -i hosts playbook.yml -u user If you still get the error, run below and paste the out-put here. ansible-playbook -i hosts playbook.yml -u user -vvv