Reputation: 79
I'm finding it difficult to run a simple playbook. I already ping target and it was successful. When i run the playbook i get this error:
PLAY [install httpd and start services] ***********************************
TASK [Gathering Facts] ****************************************************
fatal:[192.168.112.66]: UNREACHABLE!=> {"changed": false "msg": "Failed to connect to the host via ssh: [email protected]: Permission denied (publickey password)." "unreachable": true}
What's the problem with this?
Upvotes: 7
Views: 41748
Reputation: 756
In my case I copied the keys the wrong direction. What needs to happen is the ansible master node needs to copy it's key over to the target nodes, like this:
Generate the master node ssh key
ssh-keygen
then copy it to target nodes, assuming you have the password:
ssh-copy-id demo@IP_address
then ansible ping:
@ansible-master:~$ ansible TARGET-IP-ADDRESS -m ping -u USER -vvv
Upvotes: 1
Reputation: 189
See my answer here.
Basically, append the content of id_rsa.pub
file, into the authorized_keys
file.
Upvotes: 4
Reputation: 491
None of the answers given above solved the issue for me, so I have to come up with something else. The following steps helped me to run an ansible playbook on a remote host:
Generate a ssh key pair using ssh-keygen
Add the generated public key using ssh-copy-id
or manually.
Create an inventory file at /etc/ansible/hosts
and configure the remote host:
[testservers]
<remote-host-ip-address> ansible_user=<user-name> ansible_ssh_private_key_file=<absolute-path-to-your-public-ssh-key>
Run your ansible playbook
Upvotes: 1
Reputation: 9
This worked for me
ssh-copy-id -i ~/.ssh/id_rsa.pub username@remote-host
Upvotes: 0
Reputation: 21
I am guessing you used a password instead of ssh-key. So at the end of your command, add
--ask-pass
Let's say you're running your playbook. Your command will become:
ansible-playbook playbook.yml --ask-pass
Upvotes: 2
Reputation: 61
The remote server is denying you the access due your key has a password. Try this before run the playbook:
$ eval `ssh-agent`
$ ssh-add /path/to/your/private/key
Then run the playbook with the options -u and --private-key pointing to the user with access permissions on remote server and the private key you use.
Upvotes: 4