1

I created a cluster and i try to reach the master node from an another Ansible server. I copied the ssh key to the master server. and i can reach it via below command, from ansible server

ssh -i ~/.ssh/id_rsa [email protected]

but i cant reach it with

sudo ansible-playbook -i hosts /etc/ansible/playbook/test.yml

And i took this error.

x.x.x.x | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host x.x.x.x port 22: Connection timed out\r\n", "unreachable": true }

May you help me please? Other server fault issues didnt help me.

Note:

x.x.x.x (this is master node ip)


PLAY [nodes] ***************************************************************************************************************** TASK [Gathering Facts] *******************************************************************************************************

ok: [t.t.t.t]

fatal: [x.x.x.x]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host x.x.x.x port 22: Connection timed out\r\n", "unreachable": true}

TASK [test] *********************************************************************************

PLAY RECAP *******************************************************************************************************************

x.x.x.x : ok=0 changed=0 unreachable=1 failed=0

t.t.t.t : ok=1 changed=0 unreachable=0 failed=1```
1

4 Answers 4

0

The ansible-playbook command probably fails because the path to the ssh-key is not defined.

Ansible recommends to use the ssh-agent:

$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa

Another way to add private key files without using ssh-agent is using ansible_ssh_private_key_file in an inventory file as explained here

https://docs.ansible.com/ansible/latest/user_guide/connection_details.html

0

Long-shot; but it might be your key permission. Try with below:

cat ~/.ssh/id_rsa.pub | ssh @ "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys"

This gets me going with ansible everytime.

0

first of all you have to set privileges to private key on your ansible server sudo chmod 600 id_rsa check you have copied public key to the manage node sudo chmod 700 id_rsa.pub check that your inventory file properly configured with correct ip check your sshd_config file in manage node there may some issues restart ssh server on both ansible main server and manage node

0

per your connectivity test, you're using ssh ... (assuming that keys are setup correctly), you run ansible playbook using sudo, that may be the reason why...

I would recommend NOT use sudo at all, as Ansible doesn't require that and your root user may have different config vs your user, so try same thing w/out sudo, it should work)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .