Repository: ansible/ansible

Issue:
ios_command: unable to show the bgp vpnv4 route
##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
ios_command

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible --version
ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  python version = 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
ansible running on MacOS 10.12.5
IOS version 15.4(3)M7

##### SUMMARY
<!--- Explain the problem briefly -->
Use ios_command module to get below output will return error.
- show ip bgp vpnv4 vrf _vrfname_ 
- show ip bgp vpnv4 vrf _vrfname_  neighbors x.x.x.x advertised-routes
- show ip bgp vpnv4 vrf _vrfname_  neighbors x.x.x.x received-routes

Below command is working fine:
- show ip bgp vpnv4 vrf _vrfname_ summary

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```
---
- name: get show output from Cisco router
  hosts: router_name
  connection: local
  gather_facts: no

  vars:
    login_provider:
      username: "username"
      password: "password"
      host: "{{ inventory_hostname }}"

  tasks:
    - name: print status output of {{ inventory_hostname }}
      ios_command:
        provider: "{{ login_provider }}"
        commands:
          - show ip bgp vpnv4 vrf _vrfname_
          - show ip bgp vpnv4 vrf _vrfname_ neighbors x.x.x.x advertised-routes
          - show ip bgp vpnv4 vrf _vrfname_ neighbors x.x.x.x received-routes
      register: output

    - name: print status output of {{ inventory_hostname }}
      debug: var=output["stdout_lines"]
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
The expected result is to print out the result as what we can see from the ios router.
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
take command "show ip bgp vpnv4 vrf _vrfname_" as a example and I pick up some of the output of -vvvv
```
2017-07-10 14:10:11,084 paramiko.transport userauth is OK
2017-07-10 14:10:11,084 paramiko.transport Auth banner: UNAUTHORIZED ACCESS IS STRICTLY PROHIBITED

2017-07-10 14:10:12,214 paramiko.transport Authentication (password) successful!
2017-07-10 14:10:12,218 p=86426 u=ivanzhu |  ssh connection done, setting terminal
 86633 1499667012.22338: Loading TerminalModule 'ios' from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/plugins/terminal/ios.py
2017-07-10 14:10:12,223 p=86426 u=ivanzhu |   86633 1499667012.22338: Loading TerminalModule 'ios' from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/plugins/terminal/ios.py
2017-07-10 14:10:12,223 p=86426 u=ivanzhu |  ssh connection has completed successfully
2017-07-10 14:10:12,223 p=86426 u=ivanzhu |  connection established to router_name in 0:00:05.121311
2017-07-10 14:10:13,118 p=86426 u=ivanzhu |  incoming request accepted on persistent socket
2017-07-10 14:10:13,118 p=86426 u=ivanzhu |  socket operation is CONTEXT
2017-07-10 14:10:13,119 p=86426 u=ivanzhu |  updating play_context for connection
2017-07-10 14:10:13,119 p=86426 u=ivanzhu |  socket operation is EXEC
2017-07-10 14:10:13,119 p=86426 u=ivanzhu |  attempting to open shell to device
2017-07-10 14:10:13,119 paramiko.transport [chan 0] Max packet in: 32768 bytes
2017-07-10 14:10:13,571 paramiko.transport [chan 0] Max packet out: 4096 bytes
2017-07-10 14:10:13,572 paramiko.transport Secsh channel 0 opened.
2017-07-10 14:10:14,041 paramiko.transport [chan 0] Sesch channel 0 request ok
2017-07-10 14:10:14,493 paramiko.transport [chan 0] Sesch channel 0 request ok
2017-07-10 14:10:15,706 p=86426 u=ivanzhu |  shell successfully opened
2017-07-10 14:10:15,706 p=86426 u=ivanzhu |  socket operation completed with rc 0
2017-07-10 14:10:16,337 p=85773 u=ivanzhu |  open_shell() returned 0  86426 1499667007.09629: Loading Connection 'ssh' from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ansible/plugins/connection/ssh.py (found_in_cache=False, class_only=True)
ok
2017-07-10 14:10:16,339 p=85773 u=ivanzhu |   86373 1499667016.33913: ANSIBALLZ: Using lock for ios_command
2017-07-10 14:10:16,339 p=85773 u=ivanzhu |   86373 1499667016.33943: ANSIBALLZ: Acquiring lock
2017-07-10 14:10:16,339 p=85773 u=ivanzhu |   86373 1499667016.33967: ANSIBALLZ: Lock acquired: 4391446992
2017-07-10 14:10:16,340 p=85773 u=ivanzhu |   86373 1499667016.33987: ANSIBALLZ: Creating module
2017-07-10 14:10:16,431 p=85773 u=ivanzhu |   86373 1499667016.43189: ANSIBALLZ: Writing module
2017-07-10 14:10:16,432 p=85773 u=ivanzhu |   86373 1499667016.43240: ANSIBALLZ: Renaming module
2017-07-10 14:10:16,432 p=85773 u=ivanzhu |   86373 1499667016.43270: ANSIBALLZ: Done creating module
2017-07-10 14:10:16,433 p=85773 u=ivanzhu |  Using module file /Users/ivanzhu/Documents/Script/ansible/lib/ansible/modules/network/ios/ios_command.py
2017-07-10 14:10:16,433 p=85773 u=ivanzhu |   86373 1499667016.43377: _low_level_execute_command(): starting
2017-07-10 14:10:16,434 p=85773 u=ivanzhu |   86373 1499667016.43400: _low_level_execute_command(): executing: /bin/sh -c 'echo ~ && sleep 0'
2017-07-10 14:10:16,434 p=85773 u=ivanzhu |   86373 1499667016.43443: in local.exec_command()
2017-07-10 14:10:16,434 p=85773 u=ivanzhu |   86373 1499667016.43466: opening command with Popen()
2017-07-10 14:10:16,438 p=85773 u=ivanzhu |   86373 1499667016.43866: done running command with Popen()
2017-07-10 14:10:16,439 p=85773 u=ivanzhu |   86373 1499667016.43921: getting output with communicate()
2017-07-10 14:10:16,446 p=85773 u=ivanzhu |   86373 1499667016.44662: done communicating
2017-07-10 14:10:16,446 p=85773 u=ivanzhu |   86373 1499667016.44690: done with local.exec_command()
2017-07-10 14:10:16,447 p=85773 u=ivanzhu |   86373 1499667016.44714: _low_level_execute_command() done: rc=0, stdout=/Users/ivanzhu
, stderr=
2017-07-10 14:10:16,447 p=85773 u=ivanzhu |   86373 1499667016.44738: _low_level_execute_command(): starting
2017-07-10 14:10:16,447 p=85773 u=ivanzhu |   86373 1499667016.44756: _low_level_execute_command(): executing: /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/ivanzhu/.ansible/tmp/ansible-tmp-1499667016.43-119893136242754 `" && echo ansible-tmp-1499667016.43-119893136242754="` echo /Users/ivanzhu/.ansible/tmp/ansible-tmp-1499667016.43-119893136242754 `" ) && sleep 0'
2017-07-10 14:10:16,447 p=85773 u=ivanzhu |   86373 1499667016.44776: in local.exec_command()
2017-07-10 14:10:16,448 p=85773 u=ivanzhu |   86373 1499667016.44797: opening command with Popen()
2017-07-10 14:10:16,451 p=85773 u=ivanzhu |   86373 1499667016.45102: done running command with Popen()
2017-07-10 14:10:16,451 p=85773 u=ivanzhu |   86373 1499667016.45147: getting output with communicate()
2017-07-10 14:10:16,462 p=85773 u=ivanzhu |   86373 1499667016.46232: done communicating
2017-07-10 14:10:16,462 p=85773 u=ivanzhu |   86373 1499667016.46254: done with local.exec_command()
2017-07-10 14:10:16,462 p=85773 u=ivanzhu |   86373 1499667016.46277: _low_level_execute_command() done: rc=0, stdout=ansible-tmp-1499667016.43-119893136242754=/Users/ivanzhu/.ansible/tmp/ansible-tmp-1499667016.43-119893136242754
, stderr=
2017-07-10 14:10:16,470 p=85773 u=ivanzhu |   86373 1499667016.46303: transferring module to remote /Users/ivanzhu/.ansible/tmp/ansible-tmp-1499667016.43-119893136242754/ios_command.py
2017-07-10 14:10:16,473 p=85773 u=ivanzhu |   86373 1499667016.47299: done transferring module to remote
2017-07-10 14:10:16,473 p=85773 u=ivanzhu |   86373 1499667016.47344: _low_level_execute_command(): starting
2017-07-10 14:10:16,473 p=85773 u=ivanzhu |   86373 1499667016.47369: _low_level_execute_command(): executing: /bin/sh -c 'chmod u+x /Users/ivanzhu/.ansible/tmp/ansible-tmp-1499667016.43-119893136242754/ /Users/ivanzhu/.ansible/tmp/ansible-tmp-1499667016.43-119893136242754/ios_command.py && sleep 0'
2017-07-10 14:10:16,474 p=85773 u=ivanzhu |   86373 1499667016.47397: in local.exec_command()
2017-07-10 14:10:16,474 p=85773 u=ivanzhu |   86373 1499667016.47428: opening command with Popen()
2017-07-10 14:10:16,477 p=85773 u=ivanzhu |   86373 1499667016.47763: done running command with Popen()
2017-07-10 14:10:16,478 p=85773 u=ivanzhu |   86373 1499667016.47809: getting output with communicate()
2017-07-10 14:10:16,488 p=85773 u=ivanzhu |   86373 1499667016.48800: done communicating
2017-07-10 14:10:16,488 p=85773 u=ivanzhu |   86373 1499667016.48823: done with local.exec_command()
2017-07-10 14:10:16,488 p=85773 u=ivanzhu |   86373 1499667016.48843: _low_level_execute_command() done: rc=0, stdout=, stderr=
2017-07-10 14:10:16,488 p=85773 u=ivanzhu |   86373 1499667016.48860: _low_level_execute_command(): starting
2017-07-10 14:10:16,488 p=85773 u=ivanzhu |   86373 1499667016.48879: _low_level_execute_command(): executing: /bin/sh -c '/usr/bin/python /Users/ivanzhu/.ansible/tmp/ansible-tmp-1499667016.43-119893136242754/ios_command.py; rm -rf "/Users/ivanzhu/.ansible/tmp/ansible-tmp-1499667016.43-119893136242754/" > /dev/null 2>&1 && sleep 0'
2017-07-10 14:10:16,489 p=85773 u=ivanzhu |   86373 1499667016.48897: in local.exec_command()
2017-07-10 14:10:16,489 p=85773 u=ivanzhu |   86373 1499667016.48917: opening command with Popen()
2017-07-10 14:10:16,492 p=85773 u=ivanzhu |   86373 1499667016.49203: done running command with Popen()
2017-07-10 14:10:16,492 p=85773 u=ivanzhu |   86373 1499667016.49265: getting output with communicate()
2017-07-10 14:10:16,760 p=86426 u=ivanzhu |  incoming request accepted on persistent socket
2017-07-10 14:10:16,760 p=86426 u=ivanzhu |  socket operation is EXEC
2017-07-10 14:10:20,422 p=86426 u=ivanzhu |  socket operation completed with rc 1
2017-07-10 14:10:20,441 p=85773 u=ivanzhu |   86373 1499667020.44182: done communicating
2017-07-10 14:10:20,442 p=85773 u=ivanzhu |   86373 1499667020.44213: done with local.exec_command()
2017-07-10 14:10:20,442 p=85773 u=ivanzhu |   86373 1499667020.44249: _low_level_execute_command() done: rc=0, stdout=
{"msg": "ternal, a additional-path, c RIB-compressed, \r\nOrigin codes: i - IGP, e - EGP, ? - incomplete\r\nRPKI validation codes: V valid, I invalid, N Not found\r\n\r\n     Network          Next Hop            Metric LocPrf Weight Path\r\nRoute Distinguisher: 65001:100 (de", "failed": true, "rc": 1, "invocation": {"module_args": {"username": null, "authorize": null, "commands": ["show ip bgp vpnv4 vrf _vrfname_"], "ssh_keyfile": null, "retries": 10, "password": null, "auth_pass": null, "interval": 1, "host": null, "timeout": null, "provider": {"username": "username", "authorize": null, "ssh_keyfile": null, "auth_pass": null, "host": "router_name", "timeout": null, "password": null, "port": null}, "wait_for": null, "port": null, "match": "all"}}}
, stderr=
2017-07-10 14:10:20,443 p=85773 u=ivanzhu |   86373 1499667020.44307: done with _execute_module (ios_command, {'_ansible_version': '2.3.1.0', u'commands': [u'show ip bgp vpnv4 vrf _vrfname_'], '_ansible_selinux_special_fs': [u'fuse', u'nfs', u'vboxsf', u'ramfs', u'9p'], '_ansible_no_log': False, '_ansible_module_name': u'ios_command', u'provider': {u'username': u'username', 'authorize': None, 'ssh_keyfile': None, 'auth_pass': None, u'host': u'router_name', 'timeout': None, 'password': None, 'port': None}, '_ansible_verbosity': 4, '_ansible_syslog_facility': u'LOG_USER', '_ansible_socket': u'/Users/ivanzhu/.ansible/pc/98d4739804', '_ansible_diff': False, '_ansible_debug': True, '_ansible_check_mode': False})
2017-07-10 14:10:20,443 p=85773 u=ivanzhu |   86373 1499667020.44343: handler run complete
2017-07-10 14:10:20,443 p=85773 u=ivanzhu |   86373 1499667020.44382: attempt loop complete, returning result
2017-07-10 14:10:20,444 p=85773 u=ivanzhu |   86373 1499667020.44406: _execute() done
2017-07-10 14:10:20,444 p=85773 u=ivanzhu |   86373 1499667020.44427: dumping result to json
2017-07-10 14:10:20,444 p=85773 u=ivanzhu |   86373 1499667020.44451: done dumping result, returning
2017-07-10 14:10:20,444 p=85773 u=ivanzhu |   86373 1499667020.44478: done running TaskExecutor() for router_name/TASK: print print status output of router_name
2017-07-10 14:10:20,445 p=85773 u=ivanzhu |   86373 1499667020.44509: sending task result
2017-07-10 14:10:20,445 p=85773 u=ivanzhu |   86373 1499667020.44560: done sending task result
2017-07-10 14:10:20,445 p=85773 u=ivanzhu |   86373 1499667020.44584: WORKER PROCESS EXITING
2017-07-10 14:10:20,449 p=85773 u=ivanzhu |   85773 1499667020.44928: marking router_name as failed
2017-07-10 14:10:20,449 p=85773 u=ivanzhu |   85773 1499667020.44983: marking host router_name failed, current state: HOST STATE: block=2, task=1, rescue=0, always=0, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
2017-07-10 14:10:20,450 p=85773 u=ivanzhu |   85773 1499667020.45002: ^ failed state is now: HOST STATE: block=2, task=1, rescue=0, always=0, run_state=ITERATING_COMPLETE, fail_state=FAILED_TASKS, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
2017-07-10 14:10:20,450 p=85773 u=ivanzhu |   85773 1499667020.45033: getting the next task for host router_name
2017-07-10 14:10:20,450 p=85773 u=ivanzhu |   85773 1499667020.45045: host router_name is done iterating, returning
2017-07-10 14:10:20,459 p=85773 u=ivanzhu |  fatal: [router_name]: FAILED! => {
    "changed": false,
    "failed": true,
    "invocation": {
        "module_args": {
            "auth_pass": null,
            "authorize": null,
            "commands": [
                "show ip bgp vpnv4 vrf _vrfname_"
            ],
            "host": null,
            "interval": 1,
            "match": "all",
            "password": null,
            "port": null,
            "provider": {
                "auth_pass": null,
                "authorize": null,
                "host": "router_name",
                "password": null,
                "port": null,
                "ssh_keyfile": null,
                "timeout": null,
                "username": "username"
            },
            "retries": 10,
            "ssh_keyfile": null,
            "timeout": null,
            "username": null,
            "wait_for": null
        }
    },
    "msg": "ternal, a additional-path, c RIB-compressed, \r\nOrigin codes: i - IGP, e - EGP, ? - incomplete\r\nRPKI validation codes: V valid, I invalid, N Not found\r\n\r\n     Network          Next Hop            Metric LocPrf Weight Path\r\nRoute Distinguisher: 65001:100 (de",
    "rc": 1
}
2017-07-10 14:10:20,459 p=85773 u=ivanzhu |   85773 1499667020.45942: no more pending results, returning what we have
2017-07-10 14:10:20,459 p=85773 u=ivanzhu |   85773 1499667020.45963: results queue empty
2017-07-10 14:10:20,459 p=85773 u=ivanzhu |   85773 1499667020.45974: checking for any_errors_fatal
2017-07-10 14:10:20,459 p=85773 u=ivanzhu |   85773 1499667020.45986: done checking for any_errors_fatal
2017-07-10 14:10:20,460 p=85773 u=ivanzhu |   85773 1499667020.45995: checking for max_fail_percentage
2017-07-10 14:10:20,460 p=85773 u=ivanzhu |   85773 1499667020.46005: done checking for max_fail_percentage
2017-07-10 14:10:20,460 p=85773 u=ivanzhu |   85773 1499667020.46016: checking to see if all hosts have failed and the running result is not ok
2017-07-10 14:10:20,460 p=85773 u=ivanzhu |   85773 1499667020.46024: done checking to see if all hosts have failed
2017-07-10 14:10:20,460 p=85773 u=ivanzhu |   85773 1499667020.46032: getting the remaining hosts for this loop
2017-07-10 14:10:20,460 p=85773 u=ivanzhu |   85773 1499667020.46044: done getting the remaining hosts for this loop
2017-07-10 14:10:20,460 p=85773 u=ivanzhu |   85773 1499667020.46057: building list of next tasks for hosts
2017-07-10 14:10:20,460 p=85773 u=ivanzhu |   85773 1499667020.46068: getting the next task for host router_name
2017-07-10 14:10:20,460 p=85773 u=ivanzhu |   85773 1499667020.46076: host router_name is done iterating, returning
2017-07-10 14:10:20,460 p=85773 u=ivanzhu |   85773 1499667020.46087: done building task lists
2017-07-10 14:10:20,460 p=85773 u=ivanzhu |   85773 1499667020.46094: counting tasks in each state of execution
2017-07-10 14:10:20,461 p=85773 u=ivanzhu |   85773 1499667020.46103: done counting tasks in each state of execution:
	num_setups: 0
	num_tasks: 0
	num_rescue: 0
	num_always: 0
2017-07-10 14:10:20,461 p=85773 u=ivanzhu |   85773 1499667020.46115: all hosts are done, so returning None's for all hosts
2017-07-10 14:10:20,461 p=85773 u=ivanzhu |   85773 1499667020.46124: done queuing things up, now waiting for results queue to drain
2017-07-10 14:10:20,461 p=85773 u=ivanzhu |   85773 1499667020.46132: results queue empty
2017-07-10 14:10:20,461 p=85773 u=ivanzhu |   85773 1499667020.46140: checking for any_errors_fatal
2017-07-10 14:10:20,461 p=85773 u=ivanzhu |   85773 1499667020.46148: done checking for any_errors_fatal
2017-07-10 14:10:20,461 p=85773 u=ivanzhu |   85773 1499667020.46156: checking for max_fail_percentage
2017-07-10 14:10:20,461 p=85773 u=ivanzhu |   85773 1499667020.46163: done checking for max_fail_percentage
2017-07-10 14:10:20,461 p=85773 u=ivanzhu |   85773 1499667020.46171: checking to see if all hosts have failed and the running result is not ok
2017-07-10 14:10:20,461 p=85773 u=ivanzhu |   85773 1499667020.46179: done checking to see if all hosts have failed
2017-07-10 14:10:20,461 p=85773 u=ivanzhu |   85773 1499667020.46188: getting the next task for host router_name
2017-07-10 14:10:20,462 p=85773 u=ivanzhu |   85773 1499667020.46197: host router_name is done iterating, returning
2017-07-10 14:10:20,462 p=85773 u=ivanzhu |   85773 1499667020.46205: running handlers
2017-07-10 14:10:20,463 p=85773 u=ivanzhu |  	to retry, use: --limit @/Users/ivanzhu/Documents/Script/network-automation/ansible/xxxxx.retry

2017-07-10 14:10:20,463 p=85773 u=ivanzhu |  PLAY RECAP *******************************************************************************************************************
2017-07-10 14:10:20,463 p=85773 u=ivanzhu |  router_name    : ok=0    changed=0    unreachable=0    failed=1
2017-07-10 14:10:20,463 p=85773 u=ivanzhu |   85773 1499667020.46355: RUNNING CLEANUP
2017-07-10 14:10:50,422 p=86426 u=ivanzhu |  closing shell due to sigalarm
2017-07-10 14:10:50,422 p=86426 u=ivanzhu |  closing shell on device
2017-07-10 14:10:50,423 paramiko.transport [chan 0] EOF sent (0)
2017-07-10 14:10:50,424 p=86426 u=ivanzhu |  shutting down control socket, connection was active for 0:00:43.322291 secs
2017-07-10 14:10:50,425 p=86426 u=ivanzhu |  closing connection
2017-07-10 14:10:50,425 p=86426 u=ivanzhu |  closing shell on device
2017-07-10 14:10:50,467 paramiko.transport EOF in transport thread


```

<!--- Paste verbatim command output between quotes below -->
```
PLAY [get show output from Cisco router] ************************************************************************************

TASK [print status output of router_name] *****************************************************************
fatal: [router_name]: FAILED! => {"changed": false, "failed": true, "msg": " a additional-path, c RIB-compressed, \r\nOrigin codes: i - IGP, e - EGP, ? - incomplete\r\nRPKI validation codes: V valid, I invalid, N Not found\r\n\r\n     Network          Next Hop            Metric LocPrf Weight Path\r\nRoute Distinguisher: 65001:100 (default f", "rc": 1}
	to retry, use: --limit @/Users/ivanzhu/Documents/Script/network-automation/ansible/xxxxx.retry

PLAY RECAP *******************************************************************************************************************
router_name    : ok=0    changed=0    unreachable=0    failed=1
```
I tried three commands seperately but got the same error result.


Discussion:
cc @privateip @rcarrillocruz
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
I'm getting same error for below command:

sh ip bgp neighbors xxx.xxx.xxx.x advertised-routes

Looks like the problem is that rc:1 is returned due to which ansible fails although full output should simply be returned. 

Is this a bug that creeped in ios_command as I have extensively used ios_command in past without any problems. 

I'm running this on IOS XE instead of usual IOS.

Here is command's output when directly executed in cisco device:

```
sh ip bgp neighbors xxx.xxx.xxx.x advertised-routes
BGP table version is 6, local router ID is xxx.xxx.xxx.x
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
              x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>  xxx.xxx.xxx.x   0.0.0.0                  0         xxxxx i

Total number of prefixes 1

```
please do note that if I run same command on an IP for which output is just "Total number of prefixes 0" then ios_command does not fail. 

It is only when output is huge as shown in last post, then ios_command sends failed with rc:1
Also, surprisingly, if I run the same pb over and over then sometimes I do get rc 0 due to which task is success but somehow it does not capture the complete output of command.

During last run I got this:
```

    "stdout_lines": [
        [
            "0         xxxxx i",
            "",
            "Total number of prefixes 1"
        ]
```

As you can see, it captured last 2 lines of the entire output. I ran the same command again and it broke again with rc 1
can you please provide a config to setup BGP on two routers (dummy networks and all, not needed your actual config), so I get advertised routes in the lab?
Here is setup from our lab environment:
ip prefix-list MYSECURELAYER-DENY-ALL seq 5 deny 0.0.0.0/0 le 32
ip prefix-list MYSECURELAYER-OUT seq 5 permit 192.168.101.0/24
ip prefix-list MYNETWORK-ROUTES seq 5 permit 192.168.101.0/24
ip prefix-list ISP-SUPPRESS seq 5 deny 0.0.0.0/0 le 32

router bgp 65535
 bgp log-neighbor-changes
 network 192.168.101.0
 neighbor 192.168.255.2 remote-as 65534
 neighbor 192.168.255.2 description Pretend_ISP
 neighbor 192.168.255.6 remote-as 65533
 neighbor 192.168.255.6 description Pretend_Mysecurelayer
 neighbor 192.168.255.6 prefix-list MYSECURELAYER-DENY-ALL in

For the network 192.168.101.0/24 to be advertised to the BGP neighbor, a route for that network needs to exist in the router’s routing table.  For our lab setup, we added that network as a directly attached interface on the lab router.

interface GigabitEthernet0/0/2.101
 encapsulation dot1Q 101
 ip address 192.168.101.1 255.255.255.0

Resolving patch:
diff --git a/lib/ansible/plugins/terminal/ios.py b/lib/ansible/plugins/terminal/ios.py
--- a/lib/ansible/plugins/terminal/ios.py
+++ b/lib/ansible/plugins/terminal/ios.py
@@ -41,7 +41,7 @@ class TerminalModule(TerminalBase):
         re.compile(br"invalid input", re.I),
         re.compile(br"(?:incomplete|ambiguous) command", re.I),
         re.compile(br"connection timed out", re.I),
-        re.compile(br"[^\r\n]+ not found", re.I),
+        re.compile(br"[^\r\n]+ not found"),
         re.compile(br"'[^']' +returned error code: ?\d+"),
     ]
 


Test patch: