community.routeros
community.routeros copied to clipboard
Extra lines in stdout (ROS 6.49 to 7.1.5)
SUMMARY
When I send a command to the router I get a response from the router with extra lines.
ISSUE TYPE
- Bug Report
COMPONENT NAME
routeros
ANSIBLE VERSION
ansible 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/wsl/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
COLLECTION VERSION
CONFIGURATION
[defaults]
stdout_callback = yaml
host_key_checking = False
retry_files_enabled = False
inventory = hosts.yaml
[persistent_connection]
connect_timeout = 30
command_timeout = 30
STEPS TO REPRODUCE
- name: check user is exist
hosts: mikrotik
gather_facts: false
tasks:
- name: check user is exist
community.routeros.command:
commands:
- if ([/user find name=admin] !="") do={:put "exist"}
register: exist
- debug:
var: exist
EXPECTED RESULTS
I want to get only output from line 3
ACTUAL RESULTS
I got 3 lines. First-line eq first letter of command, middle-lines = empty line(empty lines can be more than one), last line eq correct output.
if i send the command with a space at the beginning it is ok
commands:
- ' if ([/user find name=admin] !="") do={:put "exist"}'
Maybe it's related to https://docs.ansible.com/ansible/devel/collections/community/routeros/docsite/ssh-guide.html#important-notes; have you tried adding something like +cet512w
to the RouterOS admin username?
I already tried it Same output
Maybe it's related to how prompts are detected in the SSH output. If that's the case, this will not be simple to fix.
It is sad. Maybe you will try. Please
Interestingly, I see similar results when running /system resource print
. This seems to be new.
I have been playing around with this a bit. Neither downgrading ansible-core, nor downgrading ansible.netcommon, nor downgrading ansible-pylibssh, nor downgrading this collection did help. (I didn't combine any of these, maybe that would have been needed?) Maybe it's related to the RouterOS version? I have version 6.49.2 (latest release version) installed on my router.
@heuels have you seen anything like this?
I tried RouterOS 7.1 same output. Tomorrow i will try oldest version 6.47 or 6.48
Long-term 6.48.6 is ok stable 6.49 is bad
In the changelog I see only one line about ssh *) ssh - fixed "undo" functionality;
https://forum.mikrotik.com/viewtopic.php?t=180391
Yeah, what's described there is exactly what's causing our problem.
Hmm, changing +cte512w
to +ct512w
in my config reduces the problem (I get less newlines, but still the initial letter from the command - basically the same that you get).
I have admin+ct1000w1000he
and usually, I have only one empty(second) line.
What I observe in 6.49 but not in 6.48.6 or before, is that stdout contains a slash when it should be empty:
'stdout': ['/'],
'stdout_lines': [['/']]}
This breaks my validation as I have for each command:
register: result
failed_when: result.stdout | join("") != ""
I am not sure this is the same issue as described here, but it seems related to the same change in the OS...
@sgrimee prepending your command with a space (I assume right now it starts with /
) might help for the moment.
thanks @felixfontein, yes that does fix it, for lines starting not only with / but also :
I have hundreds to change... so instead I patched the plugins/module_utils/routeros.py
file with
def run_commands(module, commands, check_rc=True):
...
command = " " + command
try:
out = connection.get(command, prompt, answer)
This does the trick for me without having to change all the code. Cheers!
@felixfontein would you accept a MR with this workaround (adding a space in front of every command) until a cleaner solution can be found? I have been running with it for a year now and it does not appear to cause any harm. But without it it breaks output validation from 6.49 on...
@sgrimee I think it would be OK if this is only done for RouterOS versions where this problem actually happens (i.e. major version 6, starting at 6.49). Since the version is already retrieved it should be feasible to implement such a check - Cliconf.get_device_info()
does that, though I don't know where that information is stored and how it can be obtained in the module utils.
I'm going to reopen this since #161 is more of a band-aid than a proper fix.