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

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: 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:

[defaults]

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

Double checking host file:


[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.

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.

1 Like

Yikes…

Well, at least it got fixed :smiley:

Thanks!

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