Closed codecloudmaster closed 1 month ago
It looks like the real source of the error got lost in the network_cli wrapping code. I don't see any encode()
calls in community.routeros, which makes this more confusing.
@felixfontein Will they fix the problem?
OS: Ubuntu 22.04 Version plugin: routeros 2.8.0 Using module ssh: paramiko-3.2.0
The full traceback is:
File "/tmp/ansible_community.routeros.command_payload_peiaka_2/ansible_community.routeros.command_payload.zip/ansible_collections/community/routeros/plugins/module_utils/routeros.py", line 51, in get_capabilities
capabilities = Connection(module._socket_path).get_capabilities()
File "/tmp/ansible_community.routeros.command_payload_peiaka_2/ansible_community.routeros.command_payload.zip/ansible/module_utils/connection.py", line 200, in __rpc__
raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [router]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"commands": [
"/system resource print"
],
"interval": 1,
"match": "all",
"retries": 10,
"wait_for": null
}
},
"msg": "Expected unicode or bytes, got <class 'int'>"
}
I guess someone needs to debug this first to figure out what exactly the problem is. I cannot reproduce the problem locally, so I cannot do that. Unfortunately debugging this is harder than regular debugging, since the error likely happens somewhere in ansible.netcommon or ansible-core, and since network_cli uses some complicated mechanism to actually run things. If I could reproduce this I would try to add a lot more q.q()
statements (with this q) in various places to try to figure out where the exception actually comes from.
HI. Sorry for the long response. On Ubuntu 20.04 I did not have this error. I will try to do it on a clean Ubuntu 22.04 and then will write the result here.
Even more. I try it on another router and Ubuntu 22.04 and still do not get an error, so I think maybe the problem is on my Mikrotik conf side. If I found it I will write the result here.
@felixfontein I reproduced and made video. https://disk.yandex.ru/i/kRNa4d0FzoxzBQ
@BSMaximN thanks for the video, but to be able to debug this I need direct access to an environment where this error happens. A video unfortunately does not help.
@itcrowd007 it could be the router config, the ansible.netcommon version, the ansible-core version, the community.routeros version, the Python version, or a combination of these. I hope you can figure out some combination that might be reproducable somewhere else :)
@felixfontein @itcrowd007
The problem is in the module paramiko/util.py", line 326
, because the function b
does not know how to process variable integer
paramiko [192.168.9.41] /tmp/community.routeros/venv/lib/python3.10/site-packages/paramiko/util.py", line 326, in b
paramiko [192.168.9.41] ERROR raise TypeError(f"Expected unicode or bytes, got {type(s)}")
paramiko [192.168.9.41] ERROR TypeError: Expected unicode or bytes, got <class 'int'>
I entered the password in invertory.cfg
ansible_ssh_pass=1234567890
Solution(make the password a string):
ansible_ssh_pass='1234567890'
Ah. I was able to reproduce that, with libssh though; that results in 'int' object has no attribute 'encode'
as reported by @itcrowd007. That can be fixed in ansible.netcommon (or by forcing the password to be a string with quotes, as you did). I'm currently trying to get paramiko to work to see where it needs to be fixed...
(Either ansible-core itself or ansible.netcommon as well?)
https://github.com/ansible-collections/ansible.netcommon/pull/549 fixes the problem for me (with libssh), it might also fix the problem with paramiko since it makes sure that network_cli obtains the password as a string (and not as the type which ansible-core read from the inventory).
I also created a similar PR for ansible-core, this might fix the paramiko issue: https://github.com/ansible/ansible/pull/81029
Hi. I can confirm too: the simple solution from @felixfontein works.
I entered the password in hosts.ini ansible_pasword='1234567890'
Thank you. I should have tried it before
actually in the previous versions using pythonparamiko when using ansible, that was fine adding passwords without Quots but in the new version that use pylibssh you will got this error: FAILED! => {"changed": false, "msg": "'int' object has no attribute 'encode'"} and you should put your passwords between quotes: in the file hosts
[devices] 192.168.33.40 [devices:vars] ansible_become=yes ansible_become_method=enable ansible_network_os=ios ansible_user=your cisco device username ansible_ssh_pass='12345678' ansible_become_pass='12345678'
SUMMARY
Hello, when trying to run playbook from tutorial on two Mikrotik devices with different ROS (6 and 7), the playbook ends with an error. Run it on two diffrent mashines: Ubuntu 22.04.2 (SRV1) and Ubuntu server 20.04.6 (SRV2)
ISSUE TYPE
COMPONENT NAME
ansible.netcommon.network_cli community.routeros.routeros
ANSIBLE VERSION
COLLECTION VERSION
Outpoot of ansible-galaxy collection list ansible.netcommon (I got the same error when the version was only one)
CONFIGURATION
OS / ENVIRONMENT
Mikrotik ROS 6.49.8 and Mikrotik ROS 7.9
STEPS TO REPRODUCE
hosts file: [routers] router ansible_host=192.168.1.34
[routers:vars] ansible_connection=ansible.netcommon.network_cli ansible_network_os=community.routeros.routeros ansible_user=***** ansible_ssh_pass=****
EXPECTED RESULTS
ACTUAL RESULTS
For example from SRV2