Closed izzzhoga closed 1 year ago
This error happens while processing the output of /ip route print detail without-paging
. What is the output of that command on the specific router?
Out of curiosity, what's your ansible.netcommon
version? There has been a serious bugfix in SSH handling (when using libssh) in 5.0.0, depending on how long the output is this could be related to that.
Output for ansible-galaxy collection list ansible.netcommon
:
# /home/user/.ansible/collections/ansible_collections
Collection Version
----------------- -------
ansible.netcommon 4.1.0
# /usr/local/lib/python3.9/dist-packages/ansible_collections
Collection Version
----------------- -------
ansible.netcommon 4.1.0
Can you try upgrading to ansible.netcommon 5.x.y to see whether that fixes the problem?
Output for ansible-galaxy collection list ansible.netcommon
:
# /home/user/.ansible/collections/ansible_collections
Collection Version
----------------- -------
ansible.netcommon 5.1.1
# /usr/local/lib/python3.9/dist-packages/ansible_collections
Collection Version
----------------- -------
ansible.netcommon 4.1.0
Unfortunately, it didn't work...
TASK [function/mkt/func-mkt-get-prerequisites : Collect all facts from the device] *******************************************************************
task path: /home/user/mkt/roles/function/mkt/func-mkt-get-prerequisites/tasks/main.yml:12
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
Loading collection ansible.netcommon from /home/user/.ansible/collections/ansible_collections/ansible/netcommon
Loading collection ansible.utils from /home/user/.ansible/collections/ansible_collections/ansible/utils
redirecting (type: terminal) ansible.builtin.routeros to community.routeros.routeros
redirecting (type: cliconf) ansible.builtin.routeros to community.routeros.routeros
<mikrotik> attempting to start connection
<mikrotik> using connection plugin ansible.netcommon.network_cli
Found ansible-connection at path /usr/local/bin/ansible-connection
<mikrotik> local domain socket does not exist, starting it
<mikrotik> control socket path is /home/user/.ansible/pc/183b7d4507
<mikrotik> redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
<mikrotik> Loading collection ansible.netcommon from /home/user/.ansible/collections/ansible_collections/ansible/netcommon
<mikrotik> Loading collection ansible.utils from /home/user/.ansible/collections/ansible_collections/ansible/utils
<mikrotik> redirecting (type: terminal) ansible.builtin.routeros to community.routeros.routeros
<mikrotik> Loading collection community.routeros from /home/user/.ansible/collections/ansible_collections/community/routeros
<mikrotik> redirecting (type: cliconf) ansible.builtin.routeros to community.routeros.routeros
<mikrotik> local domain socket listeners started successfully
<mikrotik> loaded cliconf plugin ansible_collections.community.routeros.plugins.cliconf.routeros from path /home/user/.ansible/collections/ansible_collections/community/routeros/plugins/cliconf/routeros.py for network_os routeros
<mikrotik> ssh type is set to auto
<mikrotik> autodetecting ssh_type
<mikrotik> ssh type is now set to libssh
<mikrotik>
<mikrotik> local domain socket path is /home/user/.ansible/pc/183b7d4507
<mikrotik> ESTABLISH LOCAL CONNECTION FOR USER: user
<mikrotik> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/user/.ansible/tmp/ansible-local-3156589vbckw94_ `"&& mkdir "` echo /home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463 `" && echo ansible-tmp-1684898707.0947196-3158153-177839921687463="` echo /home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463 `" ) && sleep 0'
Using module file /home/user/.ansible/collections/ansible_collections/community/routeros/plugins/modules/facts.py
<mikrotik> PUT /home/user/.ansible/tmp/ansible-local-3156589vbckw94_/tmpxg2vdd89 TO /home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463/AnsiballZ_facts.py
<mikrotik> EXEC /bin/sh -c 'chmod u+x /home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463/ /home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463/AnsiballZ_facts.py && sleep 0'
<mikrotik> EXEC /bin/sh -c '/usr/bin/python3 /home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463/AnsiballZ_facts.py && sleep 0'
<mikrotik> EXEC /bin/sh -c 'rm -f -r /home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463/AnsiballZ_facts.py", line 107, in <module>
_ansiballz_main()
File "/home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463/AnsiballZ_facts.py", line 99, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463/AnsiballZ_facts.py", line 47, in invoke_module
runpy.run_module(mod_name='ansible_collections.community.routeros.plugins.modules.facts', init_globals=dict(_module_fqn='ansible_collections.community.routeros.plugins.modules.facts', _modlib_path=modlib_path),
File "/usr/lib/python3.9/runpy.py", line 210, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/tmp/ansible_community.routeros.facts_payload_dny_gvfj/ansible_community.routeros.facts_payload.zip/ansible_collections/community/routeros/plugins/modules/facts.py", line 663, in <module>
File "/tmp/ansible_community.routeros.facts_payload_dny_gvfj/ansible_community.routeros.facts_payload.zip/ansible_collections/community/routeros/plugins/modules/facts.py", line 651, in main
File "/tmp/ansible_community.routeros.facts_payload_dny_gvfj/ansible_community.routeros.facts_payload.zip/ansible_collections/community/routeros/plugins/modules/facts.py", line 455, in populate
File "/tmp/ansible_community.routeros.facts_payload_dny_gvfj/ansible_community.routeros.facts_payload.zip/ansible_collections/community/routeros/plugins/modules/facts.py", line 532, in parse_route
File "/tmp/ansible_community.routeros.facts_payload_dny_gvfj/ansible_community.routeros.facts_payload.zip/ansible_collections/community/routeros/plugins/modules/facts.py", line 474, in preprocess
IndexError: list index out of range
fatal: [mikrotik]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File \"/home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463/AnsiballZ_facts.py\", line 107, in <module>\n _ansiballz_main()\n File \"/home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463/AnsiballZ_facts.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/user/.ansible/tmp/ansible-local-3156589vbckw94_/ansible-tmp-1684898707.0947196-3158153-177839921687463/AnsiballZ_facts.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.community.routeros.plugins.modules.facts', init_globals=dict(_module_fqn='ansible_collections.community.routeros.plugins.modules.facts', _modlib_path=modlib_path),\n File \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_community.routeros.facts_payload_dny_gvfj/ansible_community.routeros.facts_payload.zip/ansible_collections/community/routeros/plugins/modules/facts.py\", line 663, in <module>\n File \"/tmp/ansible_community.routeros.facts_payload_dny_gvfj/ansible_community.routeros.facts_payload.zip/ansible_collections/community/routeros/plugins/modules/facts.py\", line 651, in main\n File \"/tmp/ansible_community.routeros.facts_payload_dny_gvfj/ansible_community.routeros.facts_payload.zip/ansible_collections/community/routeros/plugins/modules/facts.py\", line 455, in populate\n File \"/tmp/ansible_community.routeros.facts_payload_dny_gvfj/ansible_community.routeros.facts_payload.zip/ansible_collections/community/routeros/plugins/modules/facts.py\", line 532, in parse_route\n File \"/tmp/ansible_community.routeros.facts_payload_dny_gvfj/ansible_community.routeros.facts_payload.zip/ansible_collections/community/routeros/plugins/modules/facts.py\", line 474, in preprocess\nIndexError: list index out of range\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
In that case:
This error happens while processing the output of
/ip route print detail without-paging
. What is the output of that command on the specific router?
Output of /ip route print detail without-paging
I replaced the IP addresses to *, security policy :)
[user@mikrotik] > /ip route print detail without-paging
Flags: D - dynamic; X - disabled, I - inactive, A - active;
c - connect, s - static, r - rip, b - bgp, o - ospf, d - dhcp, v - vpn, m - modem, y - bgp-mpls-vpn;
H - hw-offloaded; + - ecmp
DAd dst-address=*.*.*.*/* routing-table=main pref-src="" gateway=*.*.*.*
immediate-gw=*.*.*.*%ether1 distance=1 scope=30 target-scope=10 vrf-interface=ether1
suppress-hw-offload=no
DAc dst-address=*.*.*.*/* routing-table=main gateway=ether1 immediate-gw=ether1 distance=0 scope=10
suppress-hw-offload=no local-address=*.*.*.*%ether1
I think I figured out where the problem is...
It doesn't work that way
- name: Collect only routing facts
community.routeros.facts:
gather_subset:
- routing
And so in other cases it works
- name: Do not collect routing facts
community.routeros.facts:
gather_subset:
- "!routing"
The data you printed can be parsed by the code (when replacing *
back with decimal digits). So either your replacement of IPs with *
hides a problem, or some other information sneaked in (by process of libssh/paramiko/ansible.netcommon/...), or ... no idea. Without debugging the module on in your specific situation this is hard to figure out.
How else can I help you in finding the problem? Although it's you who are helping me :)
You could modify plugins/modules/facts.py
to print the information it receives for that command to a file, to see what exactly ends up there.
Change parse_route()
in line 530 to:
def parse_route(self, data):
with open('output', 'wb') as f:
f.write(data.encode('utf-8'))
facts = dict()
data = self.preprocess(data)
for line in data:
name = self.parse_routing_mark(line)
facts[name] = dict()
for (key, value) in re.findall(self.DETAIL_RE, line):
facts[name][key] = value
return facts
Then it should first write a file output
in the current directory with the contents of the response that it cannot parse. Make sure to limit your playbook to one router (the one where it fails), since the module always writes into the same file.
The management of the company allowed to send the contents of the file without modification Output contents:
Flags: D - dynamic; X - disabled, I - inactive, A - active; c - connect, s - static, r - rip, b - bgp, o - ospf, d - dhcp, v - vpn, m - modem, y - bgp-mpls-vpn; H - hw-offloaded; + - ecmp
DAd dst-address=0.0.0.0/0 routing-table=main pref-src="" gateway=10.220.40.1 immediate-gw=10.220.40.1%ether1 distance=1 scope=30 target-scope=10 vrf-interface=ether1 suppress-hw-offload=no
DAc dst-address=10.220.40.0/24 routing-table=main gateway=ether1 immediate-gw=ether1 distance=0 scope=10 suppress-hw-offload=no local-address=10.220.40.162%ether1
Thanks a lot, this allows me to reproduce the crash! I don't have time right now to investigate, but I'll take a look later today (maybe during lunch break).
When will your changes be in the main branch?
I'll merge as soon as someone reviews / tests / ... this. (Would be great if you could try it out for example and report back, if it sounds good I'll merge.)
How can I try it?
You can either apply this modification to your local community.routeros installation, or you can try installing from my branch: ansible-galaxy collection install git+https://github.com/felixfontein/community.routeros.git,preprocess
SUMMARY
Hello, when trying to collect facts from the device, the playbook ends with an error. For me now the problem is observed for the version of MikroTik RouterOS 7.9
ISSUE TYPE
COMPONENT NAME
community.routeros.facts
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
MikroTik RouterOS 7.9
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS