ansible-collections / community.routeros

Ansible modules for managing MikroTik RouterOS instances.
https://galaxy.ansible.com/ui/repo/published/community/routeros/
GNU General Public License v3.0
99 stars 45 forks source link

Router Identity => 19 char's doesn't work correctly with routeros_command #31

Closed markmcn closed 3 years ago

markmcn commented 3 years ago
SUMMARY

When the router has a name greater than or equal to 19 char's the return from routeros_command

ISSUE TYPE
COMPONENT NAME

routeros_command command

ANSIBLE VERSION
@dev ansible-test]$ ansible --version
ansible 2.9.21
  config file = /home/markmcn/ansible-test/ansible.cfg
  configured module search path = ['/home/markmcn/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Aug 18 2020, 08:33:21) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
CONFIGURATION
dev ansible-test]$ ansible-config dump --only-changed
DEFAULT_HOST_LIST(/home/markmcn/ansible-test/ansible.cfg) = ['/home/markmcn/ansible-test/hosts']
HOST_KEY_CHECKING(/home/markmcn/ansible-test/ansible.cfg) = False
OS / ENVIRONMENT

Running on RHEL 8 installed using DNF Targeting Mikrotik RouterOS 6.48.2

STEPS TO REPRODUCE

set the router identity/hostname to a name of 19 char's or longer and run the play book with -v switch to see the return. if you repeat the playbook against the same device but change the identity/hostname to a shorter name you'll get the expected result as can be seen in the output with -v

---
- hosts: 'noc_x'
  become: 'no'
  order: inventory
  serial: 1
  #  gather_facts: false

  tasks:

  - name: Check current firmware version
    routeros_command:
      commands:
        - :put [/system routerboard get current-firmware ]
    register: current_fw
EXPECTED RESULTS

Expecting the current firmware version to be returned as is shown in the output below

ansible-playbook -v ./debug.yml 
Using /home/markmcn/ansible-test/ansible.cfg as config file

PLAY [noc_x] *******************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************
ok: [dev-rt.i.domain.xx]

TASK [Check current firmware version] ******************************************************************************************************************************************************************************************************
ok: [dev-rt.i.domain.xx] => {"changed": false, "stdout": ["6.48.2"], "stdout_lines": [["6.48.2"]]}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************
dev-rt.i.domain.xx       : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
ACTUAL RESULTS

After collecting the expected result above I logged into the test device and changed the hostname/identity to ThisIsAReallyLongName and repeated the test. Notice how the stdout of the return now contains mangled copies of the ROS command issued. If you shorten the hostname under the 19 char limit the result goes back to being as expected.

 ansible-playbook -v ./debug.yml 
Using /home/markmcn/ansible-test/ansible.cfg as config file

PLAY [noc_x] *******************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************
ok: [dev-rt.i.domain.xx]

TASK [Check current firmware version] ******************************************************************************************************************************************************************************************************
ok: [dev-rt.i.domain.xx] => {"changed": false, "stdout": [":put [/system routerboard get current-firmware \n<ystem routerboard get current-firmware ]                                      \n<ystem routerboard get current-firmware ]\n<ystem routerboard get current-firmware ]\n\n6.48.2"], "stdout_lines": [[":put [/system routerboard get current-firmware ", "<ystem routerboard get current-firmware ]                                      ", "<ystem routerboard get current-firmware ]", "<ystem routerboard get current-firmware ]", "", "6.48.2"]]}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************
dev-rt.i.domain.xx       : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
heuels commented 3 years ago

Hey @markmcn, thank you for opening an issue. This actually is a very well-known problem and there are two ways to mitigate it. You can add +cet512w to your username in the playbook to make RouterOS think that your terminal width is 512 columns:

---
example_routeros:
    ansible_host: 192.168.88.1
    ansible_user: admin+cet512w
    ansible_ssh_pass: ''
    ansible_network_os: routeros
    ansible_connection: network_cli

Or you can use routeros_api module, which uses RouterOS API and therefore does not face terminal-related issues.

markmcn commented 3 years ago

Hi Egor, Thanks for getting back about this issue, Sorry I didn't mean to duplicate reporting of the issue. Cheers for the help

heuels commented 3 years ago

@markmcn, no worries, to be fair we should probably have this documented somewhere 😅