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

Fatal during task execution #51

Open offlinejke opened 2 years ago

offlinejke commented 2 years ago
SUMMARY

I have a list of MikroTik cAP ac in my inventory. On some devices, task crashes when doing a simple task, while others do it successfully. fatal: [router]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "timeout value 30 seconds reached while trying to send command: b'/system resource print'"}

ISSUE TYPE
COMPONENT NAME

community.routeros.command

ANSIBLE VERSION
ansible [core 2.11.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.5/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.5.3 (default, Apr  5 2021, 09:00:41) [GCC 6.3.0 20170516]
  jinja version = 2.11.3
  libyaml = False
COLLECTION VERSION
# /usr/local/lib/python3.5/dist-packages/ansible_collections
Collection         Version
------------------ -------
community.routeros 1.2.0

# /root/.ansible/collections/ansible_collections
Collection         Version
------------------ -------
community.routeros 1.2.0
CONFIGURATION
DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = ['/etc/ansible/hosts']
DEFAULT_PRIVATE_KEY_FILE(/etc/ansible/ansible.cfg) = /root/.ssh/id_rsa
OS / ENVIRONMENT

cAP ac firmware: 6.48.4 board-name: cAP ac model: RBcAPGi-5acD2nD revision: r2 serial-number: B9320B9EF0D4 firmware-type: ipq4000L factory-firmware: 6.44 OS Distributor ID: Debian Description: Debian GNU/Linux 9.13 (stretch) Release: 9.13 Codename: stretch

STEPS TO REPRODUCE

[community] host ansible_host=10.10.5.105 [community:vars] ansible_connection=ansible.netcommon.network_cli ansible_network_os=community.routeros.routeros ansible_user=user ansible_ssh_private_key_file=/root/.ssh/id_rsa ansible_connection=network_cli ansible_ssh_extra_args='-o StrictHostKeyChecking=no'

- name: RouterOS test with network_cli connection
  hosts: community
  gather_facts: false
  connection: ansible.netcommon.network_cli
  vars:
    ansible_python_interpreter: "{{ ansible_playbook_python }}"
  tasks:

    - name: Get Firmware
      community.routeros.command:
        commands: - /system routerboard print
      register: output
EXPECTED RESULTS

ok: [host]

ACTUAL RESULTS

fatal: [host]: FAILED! => {"changed": false, "msg": "timeout value 30 seconds reached while trying to send command: b'/system resource print'"} or fatal: [host]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "timeout value 30 seconds reached while trying to send command: b'/system resource print'"}

/usr/local/lib/python3.5/dist-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.5 support will be dropped in the next release of cryptography. Please upgrade your Python.
  from cryptography.exceptions import InvalidSignature
ansible-playbook [core 2.11.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.5/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.5.3 (default, Apr  5 2021, 09:00:41) [GCC 6.3.0 20170516]
  jinja version = 2.11.3
  libyaml = False
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: cap-office-backup ***************************************************************************************************************************************************************************************
1 plays in cap-office-backup

PLAY [RouterOS test with network_cli connection] ******************************************************************************************************************************************************************
META: ran handlers

TASK [Get Firmware] ***********************************************************************************************************************************************************************************************
task path: /etc/ansible/cap-office-backup:9
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
<10.10.5.105> ESTABLISH LOCAL CONNECTION FOR USER: root
<10.10.5.105> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-31895pgb851rm `"&& mkdir "` echo /root/.ansible/tmp/ansible-local-31895pgb851rm/ansible-tmp-1632405069.1125197-31938-187202320516234 `" && echo ansible-tmp-1632405069.1125197-31938-187202320516234="` echo /root/.ansible/tmp/ansible-local-31895pgb851rm/ansible-tmp-1632405069.1125197-31938-187202320516234 `" ) && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/community/routeros/plugins/modules/command.py
<10.10.5.105> PUT /root/.ansible/tmp/ansible-local-31895pgb851rm/tmpm79bs6ky TO /root/.ansible/tmp/ansible-local-31895pgb851rm/ansible-tmp-1632405069.1125197-31938-187202320516234/AnsiballZ_command.py
<10.10.5.105> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-31895pgb851rm/ansible-tmp-1632405069.1125197-31938-187202320516234/ /root/.ansible/tmp/ansible-local-31895pgb851rm/ansible-tmp-1632405069.1125197-31938-187202320516234/AnsiballZ_command.py && sleep 0'
<10.10.5.105> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-local-31895pgb851rm/ansible-tmp-1632405069.1125197-31938-187202320516234/AnsiballZ_command.py && sleep 0'
<10.10.5.105> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-31895pgb851rm/ansible-tmp-1632405069.1125197-31938-187202320516234/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_community.routeros.command_payload_yowzf4on/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_yowzf4on/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: [host ]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "commands": [
                - "/system routerboard 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'"
}

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

Did you check you aren't affected by one of the known problems listed here? https://docs.ansible.com/ansible/devel/collections/community/routeros/docsite/ssh-guide.html#important-notes

offlinejke commented 2 years ago

I can connect by ssh. In routeros log i can see user login string. But then command don't executed or work.

felixfontein commented 2 years ago

I'm asking because of

The SSH-based modules do not support arbitrary symbols in the router’s identity. If you are having trouble connecting to your device, please make sure that your MikroTik’s identity contains only alphanumeric characters and dashes. Also make sure that the identity string is not longer than 19 characters (see issue for details). Similar problems can happen for unsupported characters in your username.

the first point in the link. That triggers exactly the behavior you describe.

offlinejke commented 2 years ago
root@deb02:/etc/ansible# cat community
- name: RouterOS test with network_cli connection
  hosts: community
  gather_facts: false
  connection: ansible.netcommon.network_cli
  tasks:
    - name: upgrade packages
      community.routeros.command:
        commands:
          - /system routerboard print

root@deb02:/etc/ansible# ansible-playbook community
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.5.3 (default, Apr  5 2021, 09:00:41) [GCC 6.3.0 20170516]. This feature will be
removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
/usr/local/lib/python3.5/dist-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.5 support will be dropped in the next release of cryptography. Please upgrade your Python.
  from cryptography.exceptions import InvalidSignature

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

TASK [upgrade packages] *******************************************************************************************************************************************************************************************
ok: [analytics]
fatal: [-coffepoint]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "timeout value 30 seconds reached while trying to send command: b'/system resource print'"}

PLAY RECAP ********************************************************************************************************************************************************************************************************
-coffepoint                : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
analytics                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0