# Ios\_config and iosxr\_config for very long configs (+50k lines)

**URL:** <https://forum.ansible.com/t/ios-config-and-iosxr-config-for-very-long-configs-50k-lines/40757>\
**Category:** Get Help\
**Tags:** cisco, ubuntu, network\
**Created:** [March 3, 2025, 7:03pm UTC](https://forum.ansible.com/t/ios-config-and-iosxr-config-for-very-long-configs-50k-lines/40757 "2025-03-03T19:03:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elektordi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/elektordi/32/7785_2.png) [@Elektordi](https://forum.ansible.com/u/Elektordi)\
**Post date:** [March 3, 2025, 7:03pm UTC](https://forum.ansible.com/t/ios-config-and-iosxr-config-for-very-long-configs-50k-lines/40757/1 "2025-03-03T19:03:22Z")

</div>

Hello,  
I’m working for some months now to automate Cisco IOS-XE and IOS-XR routers, and it works for most of the parts.

But today I’m trying to extend automation for a dozen new devices, which have between 30k and 60k lines of configuration each. (ASR1xxx and C85xx)  
Each time, I got timeout during ios\_facts and iosxr\_facts. I tried to put command timeout up to 300s, and sometimes it works, but after it fails during ios\_config and iosxr\_config tasks.

If I send the “show running-config” over ssh to those devices, I got the answer around 10 to 15 seconds, so it seems the problem is on ansible side!

I also tried to use ANSIBLE\_PERSISTENT\_LOG\_MESSAGES=True and, and in the debug log, it hangs on:

```auto
2025-03-03 17:47:51,793 p=27322 u=elektordi n=ansible | jsonrpc request: b'{"jsonrpc": "2.0", "method": "run_commands", "id": "689bbc05-933a-4d40-952a-607e6e7b4aa5", "params": [[], {"commands": ["show running-config"], "check_rc": false}]}'

```

Then nothing at all for the timeout duration. And after timeout, I got immediately hundred of log lines like

```auto
2025-03-03 17:48:51,935 p=27322 u=elektordi n=ansible | response-4: b'(parts of config, 4096 bytes)'
2025-03-03 17:48:51,935 p=27322 u=elektordi n=ansible | response-5: b'(parts of config, 4096 bytes)'
2025-03-03 17:48:51,935 p=27322 u=elektordi n=ansible | response-6: b'(parts of config, 4096 bytes)'

```

up to ‘reponse-xxx’ in the hundreds, but never reached the end of the config.

I tried to put the timeout up to 600s, but it’s not even enough to reach the end of the config, I’m not even sure increasing the timeout allows to go further down in the config…  
I also tried to find where I can configure the 4096 bytes limit on each line but didn’t find where. (buffer limit?)  
And I’m also trying to understand why I got no output before reaching the timeout…

Do anyone have an idea on how to handle this?

Thanks!

_PS: ansible version 2.17.7 on ubuntu 22.04_

---

<div class="post-metadata">

**Author:** ![Elektordi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/elektordi/32/7785_2.png) [@Elektordi](https://forum.ansible.com/u/Elektordi)\
**Post date:** [March 5, 2025, 6:28pm UTC](https://forum.ansible.com/t/ios-config-and-iosxr-config-for-very-long-configs-50k-lines/40757/2 "2025-03-05T18:28:42Z")

</div>

I think it’s a bug in network\_cli, here is a working fix:

> <https://github.com/ansible-collections/ansible.netcommon/pull/687>
>
> \##### SUMMARY
> I was having timeout problems on IOS XE and IOS XR devices with v…ery long configurations (more than 50k lines / 2M bytes). On those same devices, a "show running-config" (with pager disabled) over plain old openssh client takes about 10-15 seconds.
> Even for smaller configurations (20k lines / 700k bytes) I had to change command\_timeout up to 300 for my ansible playbook to success.
> 
> After some debug, I found that the problem is in the regex search for errors and prompt in network\_cli, which is done on the full buffer, after each 4096 bytes from the wire, so it takes an exponential time to parse it.
> My change is to only do regex search on the last 1k of the buffer, I think there is no chance of a prompt or error longer than 1k.
> It prevents timeout issues, but also greatly speed-up many tasks on those devices.
> 
> Currently, for the proof-of-concept, I hardcoded the limit in the source code, but if someone think it could benefit from being an option, I could look on changing that.
> 
> \*My initial issue: https://forum.ansible.com/t/ios-config-and-iosxr-config-for-very-long-configs-50k-lines/40757\*
> 
> \##### ISSUE TYPE
> \- Bugfix Pull Request
> 
> \##### COMPONENT NAME
> network\_cli
> 
> \##### ADDITIONAL INFORMATION
> Before changes:
> \`\`\`paste below
> 2025-03-05 16:44:30,117 p=49599 u=elektordi n=ansible | jsonrpc request: b'{"jsonrpc": "2.0", "method": "run\_commands", "id": "05b1a0f7-642a-4a03-92cb-ae5186b37d5c", "params": \[\[\], {"commands": \["show running-config"\], "check\_rc": false}\]}'
> 2025-03-05 16:49:30,642 p=49599 u=elektordi n=ansible | command timeout triggered, timeout value is 300 secs.
> See the timeout setting options in the Network Debug and Troubleshooting Guide.
> 2025-03-05 16:49:30,644 p=49599 u=elektordi n=ansible | Traceback (most recent call last):
> File "/home/elektordi/.local/lib/python3.10/site-packages/ansible/utils/jsonrpc.py", line 45, in handle\_request
> result = rpc\_method(\*args, \*\*kwargs)
> File "/home/elektordi/.ansible/collections/ansible\_collections/cisco/ios/plugins/cliconf/ios.py", line 537, in run\_commands
> out = self.send\_command(\*\*cmd)
> File "/home/elektordi/.ansible/collections/ansible\_collections/ansible/netcommon/plugins/plugin\_utils/cliconf\_base.py", line 148, in send\_command
> resp = self.\_connection.send(\*\*kwargs)
> File "/home/elektordi/.ansible/collections/ansible\_collections/ansible/netcommon/plugins/connection/network\_cli.py", line 345, in wrapped
> return func(self, \*args, \*\*kwargs)
> File "/home/elektordi/.ansible/collections/ansible\_collections/ansible/netcommon/plugins/connection/network\_cli.py", line 1005, in send
> response = self.receive(
> File "/home/elektordi/.ansible/collections/ansible\_collections/ansible/netcommon/plugins/connection/network\_cli.py", line 946, in receive
> response = self.receive\_libssh(
> File "/home/elektordi/.ansible/collections/ansible\_collections/ansible/netcommon/plugins/connection/network\_cli.py", line 909, in receive\_libssh
> if self.\_find\_prompt(resp):
> File "/home/elektordi/.ansible/collections/ansible\_collections/ansible/netcommon/plugins/connection/network\_cli.py", line 1152, in \_find\_prompt
> match = stdout\_regex.search(response)
> File "/home/elektordi/.local/lib/python3.10/site-packages/ansible/cli/scripts/ansible\_connection\_cli\_stub.py", line 186, in command\_timeout
> raise Exception(msg)
> Exception: command timeout triggered, timeout value is 300 secs.
> See the timeout setting options in the Network Debug and Troubleshooting Guide.
> \`\`\`
> 
> After change: OK, no error
> 
> I also did some timing checks on some devices using this command:
> \`time ansible -vvvv -i inventory.yaml --playbook-dir . \<DEVICE\> -m cisco.ios.ios\_command -a '{"commands":\["sh runn"\]}' -c ansible.netcommon.network\_cli\`
> 
> Device with config of 55967 lines / 2188377 bytes
> Before: Timeout
> After: Ok in 25s
> 
> Device with config of 24651 lines / 717168 bytes
> Before: Ok in 1m16s
> After: Ok in 13s
> 
> Device with config of 2740 lines / 67080 bytes
> Before: Ok in 13s
> After: Ok in 11s

---

<div class="post-metadata">

**Author:** ![KB-perByte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kb-perbyte/32/541_2.png) [@KB-perByte](https://forum.ansible.com/u/KB-perByte)\
**Post date:** [June 16, 2025, 6:05am UTC](https://forum.ansible.com/t/ios-config-and-iosxr-config-for-very-long-configs-50k-lines/40757/3 "2025-06-16T06:05:44Z")

</div>

Thank you for your contribution, @Elektordi. The PR is being staged for review.
