Score:1

Ansible to a Cisco Router :: Password Message Messing Up the Connection?

ca flag

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

Score:2
cn flag

You're trying to execute Ansible on a network device, this fails because the device lacks standard Linux commands, let alone Python interpreter.

To work around this, there's a special connection types for network devices that rely on CLI parsers rather than execution of Python code. The IOS module you're trying to use expects network_cli type connections that is setup like this:

 ansible_connection: ansible.netcommon.network_cli
 ansible_network_os: cisco.ios.ios
 ansible_become: yes
 ansible_become_method: enable
Pete avatar
ca flag
Thanks Peter for the response, apologies for the late reply. Your feedback is incredibly useful. I think the tutorials and docs I've been reading aren't very well suited for working with Cisco devices. By chance, could you recommend a good resource? Thank you!
Peter Zhabin avatar
cn flag
I would start by reading Ansible documentation on managing network devices, a good starting point is [here](https://docs.ansible.com/ansible/latest/network/user_guide/network_best_practices_2.5.html)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.