Module failure when using anisble to control cisco router

681 views
Skip to first unread message

cral

unread,
Apr 22, 2018, 11:25:52 PM4/22/18
to Ansible Project
Hi Ansible,
    I am a newbie on Ansible, Last week when I was trying to use Ansible to send command to my router Cisco 3725 in GNS3 from my miniPC (CentOS 7 64 bits, Ansible version 2.5). It keeps failing with the following issue. 192.168.1.10 (my miniPC) 192.168.1.9 (my router)

########run playbook
[root@EY ansible]# ansible-playbook router.yml -vvvvvvvvvvv
ansible-playbook 2.5.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Parsed /etc/ansible/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/default.pyc

PLAYBOOK: router.yml ***********************************************************
1 plays in router.yml

PLAY [192.168.1.9] *************************************************************
META: ran handlers

TASK [run show version on remote devices] **************************************
task path: /etc/ansible/router.yml:7
<192.168.1.9> attempting to start connection
<192.168.1.9> using connection plugin network_cli
<192.168.1.9> local domain socket does not exist, starting it
<192.168.1.9> control socket path is /root/.ansible/pc/84f038c732
<192.168.1.9> <192.168.1.9> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO 192.168.1.9
<192.168.1.9> <192.168.1.9> ssh connection done, setting terminal
<192.168.1.9> <192.168.1.9> loaded terminal plugin for network_os ios
<192.168.1.9> <192.168.1.9> loaded cliconf plugin for network_os ios
<192.168.1.9> <192.168.1.9> firing event: on_open_shell()
<192.168.1.9> <192.168.1.9> firing event: on_become
<192.168.1.9> <192.168.1.9> ssh connection has completed successfully
<192.168.1.9> connection to remote device started successfully
<192.168.1.9> local domain socket listeners started successfully
<192.168.1.9>
<192.168.1.9> local domain socket path is /root/.ansible/pc/84f038c732
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/__init__.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/common/parsing.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/six/__init__.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/basic.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/common/__init__.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/ios/ios.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/ios/__init__.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/parsing/convert_bool.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/parsing/__init__.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/_text.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/pycompat24.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/connection.py
Using module file /usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_command.py
<192.168.1.9> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.9> EXEC /bin/sh -c 'echo ~ && sleep 0'
<192.168.1.9> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1524447089.65-260313024406209 `" && echo ansible-tmp-1524447089.65-260313024406209="` echo /root/.ansible/tmp/ansible-tmp-1524447089.65-260313024406209 `" ) && sleep 0'
<192.168.1.9> PUT /root/.ansible/tmp/ansible-local-2007vWdMIN/tmpmQErXi TO /root/.ansible/tmp/ansible-tmp-1524447089.65-260313024406209/ios_command.py
<192.168.1.9> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1524447089.65-260313024406209/ /root/.ansible/tmp/ansible-tmp-1524447089.65-260313024406209/ios_command.py && sleep 0'
<192.168.1.9> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1524447089.65-260313024406209/ios_command.py && sleep 0'
<192.168.1.9> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1524447089.65-260313024406209/ > /dev/null 2>&1 && sleep 0'
ok: [192.168.1.9] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "auth_pass": null,
            "authorize": null,
            "commands": [
                "show version"
            ],
            "host": null,
            "interval": 1,
            "match": "all",
            "password": null,
            "port": null,
            "provider": null,
            "retries": 10,
            "ssh_keyfile": null,
            "timeout": null,
            "username": null,
            "wait_for": null
        }
    },
    "stdout": [
        "Cisco IOS Software, 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(25d), RELEASE SOFTWARE (fc1)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2010 by Cisco Systems, Inc.\nCompiled Wed 18-Aug-10 07:55 by prod_rel_team\n\nROM: ROMMON Emulation Microcode\nROM: 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(25d), RELEASE SOFTWARE (fc1)\n\nRTR uptime is 3 minutes\nSystem returned to ROM by unknown reload cause - suspect boot_data[BOOT_COUNT] 0x0, BOOT_COUNT 0, BOOTDATA 19\nSystem image file is \"tftp://255.255.255.255/unknown\"\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\nex...@cisco.com.\n\nCisco 3725 (R7000) processor (revision 0.1) with 124928K/6144K bytes of memory.\nProcessor board ID FTX0945W0MY\nR7000 CPU at 240MHz, Implementation 39, Rev 2.1, 256KB L2, 512KB L3 Cache\n4 FastEthernet interfaces\n6 Serial(sync/async) interfaces\nDRAM configuration is 64 bits wide with parity enabled.\n55K bytes of NVRAM.\n\nConfiguration register is 0x2102"
    ],
    "stdout_lines": [
        [
            "Cisco IOS Software, 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(25d), RELEASE SOFTWARE (fc1)",
            "Technical Support: http://www.cisco.com/techsupport",
            "Copyright (c) 1986-2010 by Cisco Systems, Inc.",
            "Compiled Wed 18-Aug-10 07:55 by prod_rel_team",
            "",
            "ROM: ROMMON Emulation Microcode",
            "ROM: 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(25d), RELEASE SOFTWARE (fc1)",
            "",
            "RTR uptime is 3 minutes",
            "System returned to ROM by unknown reload cause - suspect boot_data[BOOT_COUNT] 0x0, BOOT_COUNT 0, BOOTDATA 19",
            "System image file is \"tftp://255.255.255.255/unknown\"",
            "",
            "",
            "This product contains cryptographic features and is subject to United",
            "States and local country laws governing import, export, transfer and",
            "use. Delivery of Cisco cryptographic products does not imply",
            "third-party authority to import, export, distribute or use encryption.",
            "Importers, exporters, distributors and users are responsible for",
            "compliance with U.S. and local country laws. By using this product you",
            "agree to comply with applicable laws and regulations. If you are unable",
            "to comply with U.S. and local laws, return this product immediately.",
            "",
            "A summary of U.S. laws governing Cisco cryptographic products may be found at:",
            "",
            "If you require further assistance please contact us by sending email to",
            "exp...@cisco.com.",
            "",
            "Cisco 3725 (R7000) processor (revision 0.1) with 124928K/6144K bytes of memory.",
            "Processor board ID FTX0945W0MY",
            "R7000 CPU at 240MHz, Implementation 39, Rev 2.1, 256KB L2, 512KB L3 Cache",
            "4 FastEthernet interfaces",
            "6 Serial(sync/async) interfaces",
            "DRAM configuration is 64 bits wide with parity enabled.",
            "55K bytes of NVRAM.",
            "",
            "Configuration register is 0x2102"
        ]
    ]
}

TASK [configure top level configuration] ***************************************
task path: /etc/ansible/router.yml:15
<192.168.1.9> attempting to start connection
<192.168.1.9> using connection plugin network_cli
<192.168.1.9> found existing local domain socket, using it!
<192.168.1.9> updating play_context for connection
<192.168.1.9>
<192.168.1.9> local domain socket path is /root/.ansible/pc/84f038c732
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/__init__.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/common/parsing.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/six/__init__.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/basic.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/common/config.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/common/__init__.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/ios/ios.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/ios/__init__.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/parsing/convert_bool.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/parsing/__init__.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/_text.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/pycompat24.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/network/common/utils.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/connection.py
Using module file /usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_config.py
<192.168.1.9> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.9> EXEC /bin/sh -c 'echo ~ && sleep 0'
<192.168.1.9> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1524447090.34-174383710450736 `" && echo ansible-tmp-1524447090.34-174383710450736="` echo /root/.ansible/tmp/ansible-tmp-1524447090.34-174383710450736 `" ) && sleep 0'
<192.168.1.9> PUT /root/.ansible/tmp/ansible-local-2007vWdMIN/tmpgDDBMY TO /root/.ansible/tmp/ansible-tmp-1524447090.34-174383710450736/ios_config.py
<192.168.1.9> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1524447090.34-174383710450736/ /root/.ansible/tmp/ansible-tmp-1524447090.34-174383710450736/ios_config.py && sleep 0'
<192.168.1.9> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1524447090.34-174383710450736/ios_config.py && sleep 0'
<192.168.1.9> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-152444709
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_hfF8l5/ansible_module_ios_config.py", line 572, in <module>
    main()
  File "/tmp/ansible_hfF8l5/ansible_module_ios_config.py", line 475, in main
    config, have_banners = get_running_config(module, config)
  File "/tmp/ansible_hfF8l5/ansible_module_ios_config.py", line 373, in get_runn
    contents = get_config(module, flags=flags)
  File "/tmp/ansible_hfF8l5/ansible_modlib.zip/ansible/module_utils/network/ios/
  File "/tmp/ansible_hfF8l5/ansible_modlib.zip/ansible/module_utils/connection.p
ansible.module_utils.connection.ConnectionError: show running-config all
                        ^
% Invalid input detected at '^' marker.

RTR#

fatal: [192.168.1.9]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_ansible_hfF8l5/ansible_module_ios_config.py\", line 475, in main\n    config, hadule_ios_config.py\", line 373, in get_running_config\n    contents = get_configils/network/ios/ios.py\", line 117, in get_config\n  File \"/tmp/ansible_hfF8l5/odule_utils.connection.ConnectionError: show running-config all\r\n
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 1
}
        to retry, use: --limit @/etc/ansible/router.retry

PLAY RECAP *********************************************************************
192.168.1.9                : ok=1    changed=0    unreachable=0    failed=1

###my ansible playbook 
---
- hosts: 192.168.1.9
  gather_facts: no
  connection: local

  tasks:
  - name: run show version on remote devices
    ios_command:
      commands: show version

  - name: configure top level configuration
    ios_config:
       lines:
        - ip address 1.1.1.1 255.255.255.0
       parents: interface Fastethernet2/0
~

##my host_file

##my hosts file
[router]
192.168.1.9

[router:vars]
ansible_connection=network_cli
ansible_network_os=ios
ansible_user=root
ansible_ssh_pass=enable
ansible_become=yes
ansible_become_method=enable
ansible_ssh_common_args='-o ProxyCommand: "ssh -w %h:%p -q bastion01"'


my Router veriosn in GNS3
##my router version in GNS3

RTR#show version
Cisco IOS Software, 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(25d), RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2010 by Cisco Systems, Inc.
Compiled Wed 18-Aug-10 07:55 by prod_rel_team

ROM: ROMMON Emulation Microcode
ROM: 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(25d), RELEASE SOFTWARE (fc1)

RTR uptime is 8 minutes
System returned to ROM by unknown reload cause - suspect boot_data[BOOT_COUNT] 0x0, BOOT_COUNT 0, BOOTDATA 19
System image file is "tftp://255.255.255.255/unknown"


This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.

A summary of U.S. laws governing Cisco cryptographic products may be found at:

If you require further assistance please contact us by sending email to

Cisco 3725 (R7000) processor (revision 0.1) with 124928K/6144K bytes of memory.
Processor board ID FTX0945W0MY
R7000 CPU at 240MHz, Implementation 39, Rev 2.1, 256KB L2, 512KB L3 Cache
4 FastEthernet interfaces
6 Serial(sync/async) interfaces
DRAM configuration is 64 bits wide with parity enabled.
55K bytes of NVRAM.

Configuration register is 0x2102


scp_if_ssh= True  already
----------------------------------------------------------------------------------------------------------------------------------------------
Can anyone help me what I am doing wrong here, all the command like run can be done, however command in configure terminal mode always failed. :(  Repost it for a better view. 


Thanks a lot ! ! ! ! !

Christer Hemgren

unread,
Apr 23, 2018, 11:59:59 PM4/23/18
to Ansible Project
Hi

Try to remove 'connection: local' as you use network_cli.

Regards
Christer

cral

unread,
Apr 24, 2018, 12:20:32 AM4/24/18
to Ansible Project
Hi, I try remove connection: local but still got the same error.

Message has been deleted

Hai Thanh Tran Nguyen

unread,
Apr 24, 2018, 11:39:26 AM4/24/18
to Ansible Project
Hi, I also got this problem, I think it's error because of this:

fatal: [192.168.1.9]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_ansible_hfF8l5/ansible_module_ios_config.py\", line 475, in main\n    config, hadule_ios_config.py\", line 373, in get_running_config\n    contents = get_configils/network/ios/ios.py\", line 117, in get_config\n  File \"/tmp/ansible_hfF8l5/odule_utils.connection.ConnectionError: show running-config all\r\n

In my switch, it does not have "show running-config all" but "show running-config" or
show running-config ?
  brief       configuration without certificate data
  class-map   Show class-map information
  full        full configuration
  interface   Show interface configuration
  linenum     Display line numbers in output
  map-class   Show map class information
  policy-map  Show policy-map information
  view        View options
  |           Output modifiers
  <cr>
Reply all
Reply to author
Forward
0 new messages