大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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 omitted] Password: ####################### Cisco Router 101 ##################…

问题原文

原帖链接 · Pete · CC BY-SA 4.0

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 omitted]
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

已采纳解答

原帖链接 · Peter Zhabin · CC BY-SA 4.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-04-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。