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

issue with community.routeros.command and community.routeros.facts when there is a dash in the username #17

Closed agpy closed 3 years ago

agpy commented 3 years ago
SUMMARY

If the username contains a dash "-" (something like "ssh-admin"), the connection timeout error will appear.

ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
2.9.16 and 2.10.2
CONFIGURATION
DEFAULT_ASK_PASS(/home/phil/ansible/ansible.cfg) = False
DEFAULT_HOST_LIST(/home/phil/ansible/ansible.cfg) = ['/home/phil/ansible/myhosts']
DEPRECATION_WARNINGS(/home/phil/ansible/ansible.cfg) = False
OS / ENVIRONMENT

Debian buster

STEPS TO REPRODUCE

Make the username with a dash inside it (eg ssh-admin) for login on routeros device. And then try to start playbook with him.


- name: RouterOS test with network_cli connection
  hosts: mikrotik_server
  gather_facts: false
  tasks:

   - community.routeros.command:
      commands:
        - /system resource print
    register: system_resource_print
  - debug:
      var: system_resource_print.stdout_lines

 - community.routeros.facts:
  - debug:
      msg: "First IP address: {{ ansible_net_all_ipv4_addresses[0] }}"
EXPECTED RESULTS

PLAY [RouterOS test with network_cli connection] ****

TASK [community.routeros.command] *** ok: [172.16.10.172]

TASK [debug] **** ok: [172.16.10.172] => { "system_resource_print.stdout_lines": [ [ "uptime: 1w3d23h36m54s", " version: 6.46.8 (long-term)", " build-time: Oct/29/2020 08:29:55", " free-memory: 189.3MiB", " total-memory: 224.0MiB", " cpu: Intel(R)", " cpu-count: 4", " cpu-frequency: 2400MHz", " cpu-load: 0%", " free-hdd-space: 31.3MiB", " total-hdd-space: 63.5MiB", " write-sect-since-reboot: 3600", " write-sect-total: 3601", " architecture-name: x86_64", " board-name: CHR", " platform: MikroTik" ] ] }

TASK [community.routeros.facts] ***** ok: [172.16.10.172]

TASK [debug] **** ok: [172.16.10.172] => { "msg": "First IP address: 172.16.10.172" }

PLAY RECAP ** 172.16.10.172 : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

ACTUAL RESULTS

The full traceback is: File "/tmp/ansible_community.routeros.command_payload_jqwdps2f/ansible_community.routeros.command_payload.zip/ansible_collections/community/routeros/plugins/module_utils/routeros.py", line 74, in get_capabilities capabilities = Connection(module._socket_path).get_capabilities() File "/tmp/ansible_community.routeros.command_payload_jqwdps2f/ansible_community.routeros.command_payload.zip/ansible/module_utils/connection.py", line 195, in rpc raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code) fatal: [172.16.10.172]: FAILED! => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "invocation": { "module_args": { "commands": [ "/system resource print" ], "interval": 1, "match": "all", "retries": 10, "wait_for": null } }, "msg": "timeout value 30 seconds reached while trying to send command: b'/system resource print'" }

felixfontein commented 3 years ago

Did you see https://github.com/ansible-collections/community.routeros#prerequisites ? Maybe it's because of that.

agpy commented 3 years ago

Thank you, I verify identities on my devices and they are ok (have not arbitrary symbols). Problem appears if I insert dash in the username. If I remove a dash from the username the problem goes away.

heuels commented 3 years ago

@felixfontein, I guess we could support that — most operating systems allow alphanumeric characters, underscores and hyphens in the username. Will open a PR tomorrow, if you don't mind.