Ios_config and iosxr_config for very long configs (+50k lines)

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:

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

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

I think it’s a bug in network_cli, here is a working fix: