Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra lines in stdout (ROS 6.49 to 7.1.5) #62

Open
1rV1N-git opened this issue Dec 17, 2021 · 18 comments · Fixed by #161
Open

Extra lines in stdout (ROS 6.49 to 7.1.5) #62

1rV1N-git opened this issue Dec 17, 2021 · 18 comments · Fixed by #161

Comments

@1rV1N-git
Copy link

1rV1N-git commented Dec 17, 2021

SUMMARY

When I send a command to the router I get a response from the router with extra lines.
image

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.


@1rV1N-git
Copy link
Author

if i send the command with a space at the beginning it is ok

        commands: 
          - ' if ([/user find name=admin] !="") do={:put "exist"}'

@felixfontein
Copy link
Collaborator

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?

@1rV1N-git
Copy link
Author

1rV1N-git commented Dec 17, 2021

I already tried it
Same output

@felixfontein
Copy link
Collaborator

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.

@1rV1N-git
Copy link
Author

1rV1N-git commented Dec 17, 2021

It is sad. Maybe you will try. Please

@felixfontein
Copy link
Collaborator

Interestingly, I see similar results when running /system resource print. This seems to be new.

@felixfontein
Copy link
Collaborator

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?

@1rV1N-git
Copy link
Author

1rV1N-git commented Dec 17, 2021

I tried RouterOS 7.1 same output.
Tomorrow i will try oldest version 6.47 or 6.48

@1rV1N-git
Copy link
Author

1rV1N-git commented Dec 18, 2021

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;

@1rV1N-git
Copy link
Author

@felixfontein
Copy link
Collaborator

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).

@1rV1N-git
Copy link
Author

I have admin+ct1000w1000he and usually, I have only one empty(second) line.

@sgrimee
Copy link
Contributor

sgrimee commented Feb 1, 2022

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...

@felixfontein
Copy link
Collaborator

@sgrimee prepending your command with a space (I assume right now it starts with /) might help for the moment.

@sgrimee
Copy link
Contributor

sgrimee commented Feb 1, 2022

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!

@sgrimee
Copy link
Contributor

sgrimee commented Mar 13, 2023

@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...

@felixfontein
Copy link
Collaborator

@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.

sgrimee added a commit to ham-laru/community.routeros that referenced this issue Mar 22, 2023
sgrimee added a commit to ham-laru/community.routeros that referenced this issue Mar 22, 2023
sgrimee added a commit to ham-laru/community.routeros that referenced this issue Mar 22, 2023
sgrimee added a commit to ham-laru/community.routeros that referenced this issue Mar 23, 2023
felixfontein added a commit that referenced this issue Mar 23, 2023
* Prompt support for ROS 6.49+ (#62)

* More precise version match (#62)

* Add changelog fragment and lint (#62)

* Update changelogs/fragments/161-workaround-prompt-with-space.yml

Co-authored-by: Felix Fontein <[email protected]>

* Vendor version package to support older ansible versions (#62)

* Update plugins/module_utils/routeros.py

Co-authored-by: Felix Fontein <[email protected]>

* Update plugins/module_utils/routeros.py

Co-authored-by: Felix Fontein <[email protected]>

* move PSF-2.0.txt to LICENSES folder

---------

Co-authored-by: Felix Fontein <[email protected]>
@felixfontein
Copy link
Collaborator

I'm going to reopen this since #161 is more of a band-aid than a proper fix.

@felixfontein felixfontein reopened this Mar 23, 2023
@felixfontein felixfontein changed the title Extra lines in stdout Extra lines in stdout (ROS 6.49 to 7.1.5) Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants