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
96 stars 45 forks source link

routeros.run_command: If the command is long, the output will be corrupted. #6

Closed likeuu-user closed 3 years ago

likeuu-user commented 3 years ago
SUMMARY

If you specify a command that exceeds 60 characters, a part of the specified command is output.

ISSUE TYPE
COMPONENT NAME

community.network.routeros_command

ANSIBLE VERSION
CONFIGURATION
# ansible --version
ansible 2.10.2
# ansible-galaxy collection list
Collection         Version
------------------ -------
ansible.netcommon  1.4.1  
check_point.mgmt   2.0.0  
community.network  1.2.0  
community.routeros 0.1.1  
fortinet.fortios   1.0.15 
vyos.vyos          1.1.0  
OS / ENVIRONMENT

cat /etc/system-release

CentOS Linux release 7.8.2003 (Core)

STEPS TO REPRODUCE
abnormal pattern:
    - name: test
      community.network.routeros_command:
        commands:
          # - '/system ntp clients set enabled=yes primary-ntp=0.0.0.0 secondary-ntp=0.0.0.0 server-dns-names=ntp.nict.jp'
          - '/interface       bridge         print detail  without-paging'

normal pattern:
    - name: test
      community.network.routeros_command:
        commands:
          # - '/system ntp clients set enabled=yes primary-ntp=0.0.0.0 secondary-ntp=0.0.0.0 server-dns-names=ntp.nict.jp'
          - '/interface       bridge         print detail without-paging'
EXPECTED RESULTS
ACTUAL RESULTS

** abnormal pattern *** ok: [HAPAC202] => { "changed": false, "invocation": { "module_args": { "commands": [ "/interface bridge print detail without-paging" ], "interval": 1, "match": "all", "retries": 10, "wait_for": null } }, "stdout": [ "/interface bridge print detail without-pagin\n<ge print detail without-paging \n<ge print detail without-paging\n<ge print detail without-paging\n\nFlags: X - disabled, R - running \n 0 R ;;; defconf\n name=\"bridgeLocal\" mtu=auto actual-mtu=1500 l2mtu=1598 arp=enabled \n arp-timeout=auto mac-address=48:8F:5A:66:75:5A protocol-mode=rstp \n fast-forward=yes igmp-snooping=no auto-mac=no \n admin-mac=48:8F:5A:66:75:5A ageing-time=5m priority=0x8000 \n max-message-age=20s forward-delay=15s transmit-hold-count=6 \n vlan-filtering=no dhcp-snooping=no" ], "stdout_lines": [ [ "/interface bridge print detail without-pagin", "<ge print detail without-paging ", "<ge print detail without-paging", "<ge print detail without-paging", "", "Flags: X - disabled, R - running ", " 0 R ;;; defconf", " name=\"bridgeLocal\" mtu=auto actual-mtu=1500 l2mtu=1598 arp=enabled ", " arp-timeout=auto mac-address=48:8F:5A:66:75:5A protocol-mode=rstp ", " fast-forward=yes igmp-snooping=no auto-mac=no ", " admin-mac=48:8F:5A:66:75:5A ageing-time=5m priority=0x8000 ", " max-message-age=20s forward-delay=15s transmit-hold-count=6 ", " vlan-filtering=no dhcp-snooping=no" ] ] }

** normal pattern *** ok: [HAPAC202] => { "changed": false, "invocation": { "module_args": { "commands": [ "/interface bridge print detail without-paging" ], "interval": 1, "match": "all", "retries": 10, "wait_for": null } }, "stdout": [ "Flags: X - disabled, R - running \n 0 R ;;; defconf\n name=\"bridgeLocal\" mtu=auto actual-mtu=1500 l2mtu=1598 arp=enabled \n arp-timeout=auto mac-address=48:8F:5A:66:75:5A protocol-mode=rstp \n fast-forward=yes igmp-snooping=no auto-mac=no \n admin-mac=48:8F:5A:66:75:5A ageing-time=5m priority=0x8000 \n max-message-age=20s forward-delay=15s transmit-hold-count=6 \n vlan-filtering=no dhcp-snooping=no" ], "stdout_lines": [ [ "Flags: X - disabled, R - running ", " 0 R ;;; defconf", " name=\"bridgeLocal\" mtu=auto actual-mtu=1500 l2mtu=1598 arp=enabled ", " arp-timeout=auto mac-address=48:8F:5A:66:75:5A protocol-mode=rstp ", " fast-forward=yes igmp-snooping=no auto-mac=no ", " admin-mac=48:8F:5A:66:75:5A ageing-time=5m priority=0x8000 ", " max-message-age=20s forward-delay=15s transmit-hold-count=6 ", " vlan-filtering=no dhcp-snooping=no" ] ] }

[root@jobsv01 mikrotik]# ansible-playbook -i inventory/hosts test.yml -vvvv
ansible-playbook 2.10.2
  config file = /root/mikrotik/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.6.8 (default, Apr  2 2020, 13:34:55) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /root/mikrotik/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /root/mikrotik/inventory/hosts as it did not pass its verify_file() method
script declined parsing /root/mikrotik/inventory/hosts as it did not pass its verify_file() method
auto declined parsing /root/mikrotik/inventory/hosts as it did not pass its verify_file() method
Parsed /root/mikrotik/inventory/hosts inventory source with ini plugin
Loading collection community.network from /root/.ansible/collections/ansible_collections/community/network
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.6/site-packages/ansible/plugins/callback/default.py

PLAYBOOK: test.yml ****************************************************************************************************************************************************
Positional arguments: test.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/root/mikrotik/inventory/hosts',)
forks: 5
1 plays in test.yml

PLAY [routeros] *******************************************************************************************************************************************************
META: ran handlers

TASK [test] ***********************************************************************************************************************************************************
task path: /root/mikrotik/test.yml:55
Loading collection ansible.netcommon from /root/.ansible/collections/ansible_collections/ansible/netcommon
<192.168.12.9> attempting to start connection
<192.168.12.9> using connection plugin ansible.netcommon.network_cli
Found ansible-connection at path /usr/local/bin/ansible-connection
<192.168.12.9> local domain socket does not exist, starting it
<192.168.12.9> control socket path is /root/.ansible/pc/e65fb158c0
<192.168.12.9> Loading collection ansible.netcommon from /root/.ansible/collections/ansible_collections/ansible/netcommon
<192.168.12.9> Loading collection community.network from /root/.ansible/collections/ansible_collections/community/network
<192.168.12.9> local domain socket listeners started successfully
<192.168.12.9> loaded cliconf plugin ansible_collections.community.network.plugins.cliconf.routeros from path /root/.ansible/collections/ansible_collections/community/network/plugins/cliconf/routeros.py for network_os community.network.routeros
<192.168.12.9> 
<192.168.12.9> local domain socket path is /root/.ansible/pc/e65fb158c0
<192.168.12.9> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.12.9> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-3742u5boe25r `"&& mkdir "` echo /root/.ansible/tmp/ansible-local-3742u5boe25r/ansible-tmp-1604225621.7764585-3748-263012588570871 `" && echo ansible-tmp-1604225621.7764585-3748-263012588570871="` echo /root/.ansible/tmp/ansible-local-3742u5boe25r/ansible-tmp-1604225621.7764585-3748-263012588570871 `" ) && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/community/network/plugins/modules/routeros_command.py
<192.168.12.9> PUT /root/.ansible/tmp/ansible-local-3742u5boe25r/tmp35aqsx0j TO /root/.ansible/tmp/ansible-local-3742u5boe25r/ansible-tmp-1604225621.7764585-3748-263012588570871/AnsiballZ_routeros_command.py
<192.168.12.9> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-3742u5boe25r/ansible-tmp-1604225621.7764585-3748-263012588570871/ /root/.ansible/tmp/ansible-local-3742u5boe25r/ansible-tmp-1604225621.7764585-3748-263012588570871/AnsiballZ_routeros_command.py && sleep 0'
<192.168.12.9> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-local-3742u5boe25r/ansible-tmp-1604225621.7764585-3748-263012588570871/AnsiballZ_routeros_command.py && sleep 0'
<192.168.12.9> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-3742u5boe25r/ansible-tmp-1604225621.7764585-3748-263012588570871/ > /dev/null 2>&1 && sleep 0'
ok: [HAPAC202] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "commands": [
                "/interface       bridge         print detail   without-paging"
            ],
            "interval": 1,
            "match": "all",
            "retries": 10,
            "wait_for": null
        }
    },
    "stdout": [
        "/interface       bridge         print detail   without-pagin\n<ge         print detail   without-paging                                      \n<ge         print detail   without-paging\n<ge         print detail   without-paging\n\nFlags: X - disabled, R - running \n 0 R ;;; defconf\n     name=\"bridgeLocal\" mtu=auto actual-mtu=1500 l2mtu=1598 arp=enabled \n     arp-timeout=auto mac-address=48:8F:5A:66:75:5A protocol-mode=rstp \n     fast-forward=yes igmp-snooping=no auto-mac=no \n     admin-mac=48:8F:5A:66:75:5A ageing-time=5m priority=0x8000 \n     max-message-age=20s forward-delay=15s transmit-hold-count=6 \n     vlan-filtering=no dhcp-snooping=no"
    ],
    "stdout_lines": [
        [
            "/interface       bridge         print detail   without-pagin",
            "<ge         print detail   without-paging                                      ",
            "<ge         print detail   without-paging",
            "<ge         print detail   without-paging",
            "",
            "Flags: X - disabled, R - running ",
            " 0 R ;;; defconf",
            "     name=\"bridgeLocal\" mtu=auto actual-mtu=1500 l2mtu=1598 arp=enabled ",
            "     arp-timeout=auto mac-address=48:8F:5A:66:75:5A protocol-mode=rstp ",
            "     fast-forward=yes igmp-snooping=no auto-mac=no ",
            "     admin-mac=48:8F:5A:66:75:5A ageing-time=5m priority=0x8000 ",
            "     max-message-age=20s forward-delay=15s transmit-hold-count=6 ",
            "     vlan-filtering=no dhcp-snooping=no"
        ]
    ]
}
META: ran handlers
META: ran handlers

PLAY RECAP ************************************************************************************************************************************************************
HAPAC202                   : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
felixfontein commented 3 years ago

CC @heuels

felixfontein commented 3 years ago

@heuels I just found out I can transfer issues from community.network here, so in the future I'll just move the issue here instead of pinging you directly, since I think you get notifications for new issues here, right? :)

heuels commented 3 years ago

@felixfontein, yes thank you! That would be much more convenient for the both of us 🙂

heuels commented 3 years ago

Hey @likeuu-user, 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.

likeuu-user commented 3 years ago

Thank you @heuels. I solved it by the method I was taught.

heuels commented 3 years ago

Great! Glad I could be of help.