# Ansible can't connect to IOS switches using ssh (previously working)

**URL:** <https://forum.ansible.com/t/ansible-cant-connect-to-ios-switches-using-ssh-previously-working/7515>\
**Category:** Get Help\
**Tags:** cisco, pylibssh, ssh, paramiko, ubuntu\
**Created:** [July 27, 2024, 7:30pm UTC](https://forum.ansible.com/t/ansible-cant-connect-to-ios-switches-using-ssh-previously-working/7515 "2024-07-27T19:30:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jonathan/32/4215_2.png) [@Jonathan](https://forum.ansible.com/u/Jonathan)\
**Post date:** [July 27, 2024, 7:30pm UTC](https://forum.ansible.com/t/ansible-cant-connect-to-ios-switches-using-ssh-previously-working/7515/1 "2024-07-27T19:30:28Z")

</div>

Hey all,

I got a bit of a head scratcher. Long story short, I had to redeploy my Ubuntu VM bcuz hyper-v sucks.

Anyways, I was hoping the only thing I would have difficulty with was re-creating my hosts.ini file and my ansible.cfg file. That was not the case.

I got everything where I wanted it, and tried to run my playbook and keep getting this error:

\*\*jonathan@AnsibleVM:/etc/ansible/YAnsible-playbooks$ ansible-playbook getversion.yaml \*\*  
**[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details**  
**[WARNING]: \* Failed to parse /etc/ansible/hosts with yaml plugin: We were unable to read either as**  
**JSON nor YAML, these are the errors we got from each: JSON: Expecting value: line 2 column 2 (char**  
**2) Syntax Error while loading YAML. did not find expected The error appears to**  
**be in ‘/etc/ansible/hosts’: line 3, column 1, but may be elsewhere in the file depending on the**  
**exact syntax problem. The offending line appears to be: [switches:children] LABCAT-1DFX-01 ^ here**  
**[WARNING]: \* Failed to parse /etc/ansible/hosts with ini plugin: /etc/ansible/hosts:6: Section**  
**[switch:vars] not valid for undefined group: switch**  
**[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source**  
**[WARNING]: No inventory was parsed, only implicit localhost is available**  
**[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit**  
**localhost does not match ‘all’**

\*\*PLAY [Get interface and vers info] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\*\*TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
**fatal: [LABCAT-S04Q-02]: UNREACHABLE! =\> {“changed”: false, “msg”: “Failed to connect to the host via ssh: Unable to negotiate with 10.10.41.3 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1”, “unreachable”: true}**  
**fatal: [LABCAT-1DFX-01]: UNREACHABLE! =\> {“changed”: false, “msg”: “Failed to connect to the host via ssh: [jonathan@10.10.41.2](mailto:jonathan@10.10.41.2): Permission denied (publickey,keyboard-interactive,password).”, “unreachable”: true}**

\*\*PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\*\*LABCAT-1DFX-01 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0 \*\*  
**LABCAT-S04Q-02 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0**

**BTW, I can fully connecting using SSH and the creds used in the Ansible config.**

What I’ve tried:  
Updating the ansible.cfg file:

```auto
[defaults]

inventory = /etc/ansible/hosts
ssh_type = auto
host_key_auto_add = true
host_key_checking = false

```

Double checking host file:

```auto

[switches:children]
LABCAT-1DFX-01
LABCAT-S04Q-02

[switch:vars]
ansible_network_os=ios
ansible_user=redacted
ansible_password=redacted
ansible_connection=network_cli

[LABCAT-1DFX-01]

LABCAT-1DFX-01 ansible_host=10.10.41.2

[LABCAT-S04Q-02]

LABCAT-S04Q-02 ansible_host=10.10.41.3

```

I’ve tried generating ssh rsa keys using ssh-keygen.

Thanks, sorry I know there is a LOT of text to this one.

---

<div class="post-metadata">

**Author:** ![binbashroot](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@binbashroot](https://forum.ansible.com/u/binbashroot)\
**Post date:** [July 28, 2024, 1:54pm UTC](https://forum.ansible.com/t/ansible-cant-connect-to-ios-switches-using-ssh-previously-working/7515/2 "2024-07-28T13:54:27Z")

</div>

The group you’re running against is “switches”. The group that you tied your vars to is “switch”. Therefore your vars are not being leveraged against the “switches” group.

---

<div class="post-metadata">

**Author:** ![Jonathan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jonathan/32/4215_2.png) [@Jonathan](https://forum.ansible.com/u/Jonathan)\
**Post date:** [July 28, 2024, 4:57pm UTC](https://forum.ansible.com/t/ansible-cant-connect-to-ios-switches-using-ssh-previously-working/7515/3 "2024-07-28T16:57:01Z")

</div>

Yikes…

Well, at least it got fixed 😃

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 27, 2024, 4:57pm UTC](https://forum.ansible.com/t/ansible-cant-connect-to-ios-switches-using-ssh-previously-working/7515/4 "2024-08-27T16:57:27Z")

</div>

Closed on August 27, 2024, 4:57pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
