# Failed to connect to the host via ssh: Permission denied (publickey,password)

**URL:** <https://forum.ansible.com/t/failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password/34529>\
**Category:** Ansible Project\
**Created:** [January 28, 2021, 6:46pm UTC](https://forum.ansible.com/t/failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password/34529 "2021-01-28T18:46:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.srini](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@a.srini](https://forum.ansible.com/u/a.srini)\
**Post date:** [January 28, 2021, 6:46pm UTC](https://forum.ansible.com/t/failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password/34529/1 "2021-01-28T18:46:37Z")

</div>

I have a playbook where it has an option that can be run in 2 different ways.

1. When having single host to execute, can run prompt.yml file to execute against single host.
2. When a large number of hosts exits, that was kept in a inventory and run against them.

Play book is working fine when executing with site\_prompt.yml, but having issue when executing again site\_inventory.yml

SK [upgrade : Retrieve the current firmware] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /root/brocade/ansible-fos-command/devopsweb1/roles/brocade\_upgrade/tasks/main.yaml:1  
\<7.5.5.154\> ESTABLISH SSH CONNECTION FOR USER: None  
\<7.5.5.154\> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/c6fd0bb33a 7.5.5.154 ‘/bin/sh -c ‘"’“‘echo ~ && sleep 0’”’“‘’  
\<7.5.5.155\> ESTABLISH SSH CONNECTION FOR USER: None  
\<7.5.5.155\> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/900bdb6d71 7.5.5.155 '/bin/sh -c '”‘“‘echo ~ && sleep 0’”’"‘’  
\<7.50.52.154\> (255, b’‘, b’Permission denied (publickey,password).\r\n’)  
fatal: [7.5.5.154]: UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: Permission denied (publickey,password).”,  
“unreachable”: true  
}  
\<7.5.5.155\> (255, b’‘, b’Permission denied (publickey,password).\r\n’)  
fatal: [7.5.5.155]: UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: Permission denied (publickey,password).”,  
“unreachable”: true

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [January 28, 2021, 7:10pm UTC](https://forum.ansible.com/t/failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password/34529/2 "2021-01-28T19:10:35Z")

</div>

With this amount of provided information the only thing that can be said is that the issue is with site\_inventory.yml

---

<div class="post-metadata">

**Author:** ![a.srini](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@a.srini](https://forum.ansible.com/u/a.srini)\
**Post date:** [January 28, 2021, 8:29pm UTC](https://forum.ansible.com/t/failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password/34529/3 "2021-01-28T20:29:00Z")

</div>

Playbook: Site\_inventory.yml

- hosts: switches  
gather\_facts: False  
vars:  
ftp\_server: 2.19.16.15

tasks:

- name: Include the brocade upgrade role  
include\_role:  
name: brocade\_upgrade  
vars:  
ip\_addr: “{{ inventory\_hostname }}”

playbooks: Main.yml

- name: Retrieve the current firmware  
brocade\_fos\_command:  
switch\_login: “{{ username }}”  
switch\_password: “{{ password }}”  
switch\_address: “{{ ip\_addr}}”  
command\_set:

- command: firmwareshow  
register: firmwareshow\_output

- name: Parse the firmwareshow output  
ansible.netcommon.cli\_parse:  
text: “{{ firmwareshow\_output[‘messages’]|join(‘\n’) }}”  
parser:  
name: ansible.netcommon.native  
template\_path: “{{ role\_path }}/templates/brocade\_firmware.yaml”  
register: parsed\_firmwareshow

inventory file:

all:  
vars:  
upgrade\_path:  
v7.4.2d: “v7.4.2g”  
v8.2.1d: “v8.2.2d”  
children:  
switches:  
hosts:  
#10.1.1.2:  
#10.1.1.3:

vars:  
username: admin  
password: password

---

<div class="post-metadata">

**Author:** ![robert\_rottermann](https://avatars.discourse-cdn.com/v4/letter/r/4bbf92/32.png) [@robert\_rottermann](https://forum.ansible.com/u/robert_rottermann)\
**Post date:** [January 29, 2021, 6:02am UTC](https://forum.ansible.com/t/failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password/34529/4 "2021-01-29T06:02:49Z")

</div>

just a shot into the dark:  
could it be, that the permissions on the files in .ssh of the target are wrong?  
ssh is very picky here  
robert

---

<div class="post-metadata">

**Author:** ![a.srini](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@a.srini](https://forum.ansible.com/u/a.srini)\
**Post date:** [January 29, 2021, 7:06am UTC](https://forum.ansible.com/t/failed-to-connect-to-the-host-via-ssh-permission-denied-publickey-password/34529/5 "2021-01-29T07:06:18Z")

</div>

I am running this playbook against the switches, where it does not have an inbuilt python to execute. It has to execute in localhost and then fetch the output.  
That is working fine in prompt.yml file. but not working correctly in inventory.yml
