# ansible fail to work with ssh

**URL:** <https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [March 19, 2019, 8:18am UTC](https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908 "2019-03-19T08:18:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharanga2006](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@tharanga2006](https://forum.ansible.com/u/tharanga2006)\
**Post date:** [March 19, 2019, 8:18am UTC](https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908/1 "2019-03-19T08:18:55Z")

</div>

OS : Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-104-generic x86\_64)  
ansible : ansible 2.7.8

Problem  
I need to configure ansible to run another node without entering the password ( through ssh)

I have followed below method to setup the ssh with no password

1. I’m login to the control node with a user having root privileges

2. ssh-keygen

3. ssh-copy-id -i ~/.ssh/id\_rsa.pub remote-host

4. ssh remote-host ( works without promoting for password)

5. I copy ansible.cfg to local folder and point my inventory  
------ ansible.cfg-----  
[defaults]  
inventory = hosts  
-------ansible.cfg-----

6. my hosts file  
-------hosts-------  
[rbmqnode1]  
ansible\_user= host=  
------hosts--------

7. I ran following ansible command  
sudo ansible -m ping all  
its fail with below error

> UNREACHABLE! =\> {  
> “changed”: false,  
> “msg”: “Failed to connect to the host via ssh: Permission denied (publickey,password).”,  
> “unreachable”: true  
> }

I have went through many solutions but fail to fix this issue. inserting “ansible\_ssh\_pass” fix me the issue but I dont want to do that. Any help appropriated.

---

<div class="post-metadata">

**Author:** ![tharanga2006](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@tharanga2006](https://forum.ansible.com/u/tharanga2006)\
**Post date:** [March 19, 2019, 8:52am UTC](https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908/2 "2019-03-19T08:52:49Z")

</div>

any support highly appreciate

---

<div class="post-metadata">

**Author:** ![Sudheer\_S1](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@Sudheer\_S1](https://forum.ansible.com/u/Sudheer_S1)\
**Post date:** [March 19, 2019, 9:11am UTC](https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908/3 "2019-03-19T09:11:07Z")

</div>

What’s the point of step 5? Why are you using sudo?

---

<div class="post-metadata">

**Author:** ![Sebastian\_Meyer](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@Sebastian\_Meyer](https://forum.ansible.com/u/Sebastian_Meyer)\
**Post date:** [March 19, 2019, 9:25am UTC](https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908/4 "2019-03-19T09:25:45Z")

</div>

Is this the same user you use for normal ssh? When you did the  
ssh-copy-id you transferred the public key to the remote node only for a  
single user (I'm guessing root, as you were root on the control node and  
did not specify a user there). If that user is different from the one  
you use for ansible, then the key can't be used.

- Sebastian

---

<div class="post-metadata">

**Author:** ![tharanga2006](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@tharanga2006](https://forum.ansible.com/u/tharanga2006)\
**Post date:** [March 19, 2019, 9:43am UTC](https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908/5 "2019-03-19T09:43:27Z")

</div>

Hi,  
step five is to point my inventory ( point my hosts file )

Im using sudo because without it Im getting this error

| FAILED! =\> {  
“msg”: “Cannot write to ControlPath /home/blackbeard/.ansible/cp”  
}

---

<div class="post-metadata">

**Author:** ![tharanga2006](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@tharanga2006](https://forum.ansible.com/u/tharanga2006)\
**Post date:** [March 19, 2019, 9:44am UTC](https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908/6 "2019-03-19T09:44:38Z")

</div>

Is this the same user you use for normal ssh?  
yes.

---

<div class="post-metadata">

**Author:** ![Amit\_Bhardwaj](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@Amit\_Bhardwaj](https://forum.ansible.com/u/Amit_Bhardwaj)\
**Post date:** [March 19, 2019, 9:49am UTC](https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908/7 "2019-03-19T09:49:30Z")

</div>

Check if this link helps: [https://stackoverflow.com/questions/42421774/ansible-permission-problems](https://stackoverflow.com/questions/42421774/ansible-permission-problems)

Surely some permission issue here.

---

<div class="post-metadata">

**Author:** ![tharanga2006](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@tharanga2006](https://forum.ansible.com/u/tharanga2006)\
**Post date:** [March 19, 2019, 10:03am UTC](https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908/8 "2019-03-19T10:03:04Z")

</div>

Hi Amit,  
Thanks as I mention in my problem  
if I gave value for "ansible\_ssh\_pass= it works , But I don’t like to do that.

---

<div class="post-metadata">

**Author:** ![tharanga2006](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@tharanga2006](https://forum.ansible.com/u/tharanga2006)\
**Post date:** [March 19, 2019, 10:11am UTC](https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908/9 "2019-03-19T10:11:18Z")

</div>

I can do ssh to second server without issue with the same user but I’m getting this error when I ran the ansible command

---

<div class="post-metadata">

**Author:** ![Amit\_Bhardwaj](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@Amit\_Bhardwaj](https://forum.ansible.com/u/Amit_Bhardwaj)\
**Post date:** [March 19, 2019, 10:26am UTC](https://forum.ansible.com/t/ansible-fail-to-work-with-ssh/29908/10 "2019-03-19T10:26:09Z")

</div>

Check this link → [https://www.reddit.com/r/ansible/comments/3wetnm/i\_can\_ssh\_why\_cant\_i\_ansible/](https://www.reddit.com/r/ansible/comments/3wetnm/i_can_ssh_why_cant_i_ansible/)  
and see if that works.

In case it fails, we would like to know more about the setup like Ansible version, OS details on Ansible server and client, does it work fine with any other client or is it the same? If it works fine with another client, the issue can be limited to that particular client and not ANSIBLE as a whole. This is a very very basic setup so it should work perfectly fine.

Regards  
AB
