When I manually SSH from my Ansible server to a Cisco router, I see this on the command line:
me@ubuntu01:~/ansible$
me@ubuntu01:~/ansible$ ssh [email protected]
Password:
####################### Cisco Router 101 ########################
Hi, welcome to the company router! Pls don't mess it up.
####################### Cisco Router 101 ########################
cisco101 line 388
% Password expiration warning.
cisco101#
cisco101#
Sadly, I can't do anything about resetting that password, so I have to learn to live with that "Password expiration warning" message.
I'd like to access this router with Ansible. Obviously, SSH to the router works. So here's my POC inventory file:
[routers]
10.10.10.101
[routers:vars]
ansible_network_os=ios
ansible_ssh_user=user01
ansible_ssh_password=password123
And my playbook:
---
- hosts: routers
vars:
ansible_python_interpreter: auto
- tasks:
- name: Gather only the config and default facts
cisco.ios.ios_facts:
gather_subset:
- config
But alas:
me@ubuntu01:~/ansible$
me@ubuntu01:~/ansible$
me@ubuntu01:~/ansible$ ansible-playbook myPlaybook.yml -i /home/me/inventory.txt
PLAY [routers] **********************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************
Monday 10 April 2023 19:31:48 +0000 (0:00:00.061) 0:00:00.061 **********
[WARNING]: Ignoring timeout(10) for ansible.legacy.ios_facts
[WARNING]: Unhandled error in Python interpreter discovery for host 10.10.10.101: unexpected output from Python interpreter
discovery
fatal: [10.10.10.101]: FAILED! => changed=false
ansible_facts: {}
failed_modules:
ansible.legacy.ios_facts:
ansible_facts:
discovered_interpreter_python: /usr/bin/python
failed: true
module_stderr: ''
module_stdout: |-
C
####################### Cisco Router 101 ########################
Hi, welcome to the company router! Pls don't mess it up.
####################### Cisco Router 101 ########################
cisco101 line 388
Line has invalid autocommand "/bin/sh -c '/usr/bin/python && sleep 0'"
msg: |-
MODULE FAILURE
See stdout/stderr for the exact error
rc: 0
warnings:
- Platform unknown on host 10.10.10.101 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible/2.10/reference_appendices/interpreter_discovery.html for more information.
msg: |-
The following modules failed to execute: ansible.legacy.ios_facts
PLAY RECAP ********************************************************************************************************************
10.10.10.101 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Playbook run took 0 days, 0 hours, 0 minutes, 3 seconds
Monday 10 April 2023 19:31:52 +0000 (0:00:03.741) 0:00:03.802 **********
===============================================================================
Gathering Facts --------------------------------------------- 3.74s
me@ubuntu01:~/ansible$
Before I go any further:
- My Ubuntu is Ubuntu 18.04.5 LTS
- My Ansible is version ansible 2.10.7 (Python ver 3.6.9)
- My Ansible-Playbook is version 2.10.7 (Python ver 3.6.9)
- The router is running Cisco IOS Version 15.4(3)M3 (not IOS XR)
Okay: So what's going wrong? Two possibilities, as I see it:
(A) That "Password expiration warning" that I see when I manually log it could be confusing Ansible, I suppose.
(B) The Cisco router is running a lesser version of Python, causing Ansible to choke.
As far as I can tell, the router isn't running any version of python. Or at least, I can't find a "show python version" command on the router to verify otherwise.
My gut instinct tells me that (A) is the problem. If that's the case, is there any way to teach Ansible to ignore the "Password expiration warning" message? And if the problem is (B)... what do I do? Thanks