Ansible ios_command module - Failure execution basic commands on a Cisco IOS device

Hello

Ansible version: 2.3.0.0
Python version = 2.7.13 (default, May 11 2017, 16:44:39) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]
Host : CentOS release 6.9 (Final)
Paramiko version : 2.1.2

I’m trying to use ansible and ansible ios_command to execute a basic ‘show version’ command on a cisco catalyst 6500 switch.

in my environment, the host running Ansible has private keys, and can connect to Cisco devices without password just by public key authentication. I can ssh to the Router_65 from host with no password.

basically when I run the adhoc ansible command : ansible router_65 -m raw -a ‘show ver’ -vvv
this works well and I can see the output. I realized that the above adhoc ansible command uses the default openssh client in OS.

But I would like to get better output in order to parse it. I looked at ntc-ansible and ios_command modules.

I couldn’t get any of these 2 working as they both are based on paramiko (Python SSH agent). Paramiko seems to be the problem for me to get this working.

to start I created a simple playbook:

root@host/ansible cat show_ver.yml

here is my way ios_command it work well

cat /etc/ansible/hosts

[cisco]
10.101.24.241 ansible_ssh_user=cisco ansible_ssh_pass=cisco123

root@ansible:~# ansible cisco -c local -m ios_command -a “commands=‘show version’”
10.101.24.241 | SUCCESS => {
“changed”: false,
“stdout”: [
“Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 12.2(44)SE6, RELEASE SOFTWARE (fc1)\nCopyright (c) 1986-2009 by Cisco Systems, Inc.\nCompiled Mon 09-Mar-09 18:10 by gereddy\nImage text-base: 0x00003000, data-base: 0x01100000\n\nROM: Bootstrap program is C2960 boot loader\nBOOTLDR: C2960 Boot Loader (C2960-HBOOT-M) Version 12.2(44)SE6, RELEASE SOFTWARE (fc1)\n\nc2960 uptime is 14 weeks, 2 days, 22 hours, 4 minutes\nSystem returned to ROM by power-on\nSystem image file is "flash:c2960-lanbasek9-mz.122-44.SE6/c2960-lanbasek9-mz.122-44.SE6.bin"\n\n\nThis product contains cryptographic features and is subject to United\nStates and local country laws governing import, export, transfer and\nuse. Delivery of Cisco cryptographic products does not imply\nthird-party authority to import, export, distribute or use encryption.\nImporters, exporters, distributors and users are responsible for\ncompliance with U.S. and local country laws. By using this product you\nagree to comply with applicable laws and regulations. If you are unable\nto comply with U.S. and local laws, return this product immediately.\n\nA summary of U.S. laws governing Cisco cryptographic products may be found at:\nhttp://www.cisco.com/wwl/export/crypto/tool/stqrg.html\n\nIf you require further assistance please contact us by sending email to\nexport@cisco.com.\n\ncisco WS-C2960G-24TC-L (PowerPC405) processor (revision H0) with 61440K/4088K bytes of memory.\nProcessor board ID FOC1431X2HG\nLast reset from power-on\n4 Virtual Ethernet interfaces\n24 Gigabit Ethernet interfaces\nThe password-recovery mechanism is enabled.\n\n64K bytes of flash-simulated non-volatile configuration memory.\nBase ethernet MAC Address : E8:04:62:18:34:80\nMotherboard assembly number : 73-10015-09\nPower supply part number : 341-0098-02\nMotherboard serial number : FOC14316AK4\nPower supply serial number : AZS142805WG\nModel revision number : H0\nMotherboard revision number : A0\nModel number : WS-C2960G-24TC-L\nSystem serial number : FOC1431X2HG\nTop Assembly Part Number : 800-26673-06\nTop Assembly Revision Number : A0\nVersion ID : V06\nCLEI Code Number : COMP300ARA\nHardware Board Revision Number : 0x01\n\n\nSwitch Ports Model SW Version SW Image \n------ ----- ----- ---------- ---------- \n* 1 24 WS-C2960G-24TC-L 12.2(44)SE6 C2960-LANBASEK9-M \n\n\nConfiguration register is 0xF”

在 2017年5月23日星期二 UTC+8上午6:11:29,Reza Toghraee写道: