community.routeros
community.routeros copied to clipboard
file set command issue (asks for '=')
SUMMARY
Hello!
I try upload ssh public key to the mikrotik (RouterOS v7.6 stable) in the following way:
- name: Generate empty ssh pub key
community.routeros.api:
path: "file"
cmd: "print file=id_rsa.pub"
- name: Put content to the ssh pub key
community.routeros.api:
path: "file"
cmd: 'set id_rsa.pub.txt contents="{{ ssh_pub_key }}"'
The following error has appeared:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible_collections.community.routeros.plugins.module_utils.quoting.ParseError: missing '=' after 'id_rsa.pub.txt'
Under routeros cli comannds:
/file print file=id_rsa.pub
/file set id_rsa.pub.txt contents="test"
work as expected.
Any help will be appreciated.
regards Serhiy.
ISSUE TYPE
- Bug Report
COMPONENT NAME
community.routeros.api
ANSIBLE VERSION
ansible [core 2.14.4]
config file = /Users/gray/projects/ansible/routers/ansible.cfg
configured module search path = ['/Users/gray/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/gray/projects/ansible/venv/lib/python3.9/site-packages/ansible
ansible collection location = /Users/gray/.ansible/collections:/usr/share/ansible/collections
executable location = /Users/gray/projects/ansible/venv/bin/ansible
python version = 3.9.6 (default, Mar 10 2023, 20:16:38) [Clang 14.0.3 (clang-1403.0.22.14.1)] (/Users/gray/projects/ansible/venv/bin/python)
jinja version = 3.1.2
libyaml = True
COLLECTION VERSION
ansible-galaxy collection list community.routeros
# ~/.ansible/collections/ansible_collections
Collection Version
------------------ -------
community.routeros 2.8.0
# ~/projects/ansible/venv/lib/python3.9/site-packages/ansible_collections
Collection Version
------------------ -------
community.routeros 2.8.0
CONFIGURATION
CONFIG_FILE() = ~/projects/ansible/routers/ansible.cfg
DEFAULT_HOST_LIST(~/projects/ansible/routers/ansible.cfg) = ['/Users/gray/projects/ansible/routers/hosts.yml']
OS / ENVIRONMENT
ProductName: macOS ProductVersion: 13.3.1 BuildVersion: 22E261
STEPS TO REPRODUCE
- name: Generate empty ssh pub key
community.routeros.api:
path: "file"
cmd: "print file=id_rsa.pub"
- name: Put content to the ssh pub key
community.routeros.api:
path: "file"
cmd: 'set id_rsa.pub.txt contents="{{ ssh_pub_key }}"'
EXPECTED RESULTS
Contents from variable should be placed into the file.
ACTUAL RESULTS
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible_collections.community.routeros.plugins.module_utils.quoting.ParseError: missing '=' after 'id_rsa.pub.txt'
TASK [Put content to the ssh pub key] *************************************************************************************************************
fatal: [mikrotik]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"~//.ansible/tmp/ansible-local-22960vt0f6yot/ansible-tmp-1681564975.694714-23025-254122928642250/AnsiballZ_api.py\", line 107, in <module>\n _ansiballz_main()\n File \"~//.ansible/tmp/ansible-local-22960vt0f6yot/ansible-tmp-1681564975.694714-23025-254122928642250/AnsiballZ_api.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"~//.ansible/tmp/ansible-local-22960vt0f6yot/ansible-tmp-1681564975.694714-23025-254122928642250/AnsiballZ_api.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.community.routeros.plugins.modules.api', init_globals=dict(_module_fqn='ansible_collections.community.routeros.plugins.modules.api', _modlib_path=modlib_path),\n File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 210, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/var/folders/p2/xtr9ql715bd78nvs0v71x25m0000gn/T/ansible_community.routeros.api_payload_n8r02h0l/ansible_community.routeros.api_payload.zip/ansible_collections/community/routeros/plugins/modules/api.py\", line 577, in <module>\n File \"/var/folders/p2/xtr9ql715bd78nvs0v71x25m0000gn/T/ansible_community.routeros.api_payload_n8r02h0l/ansible_community.routeros.api_payload.zip/ansible_collections/community/routeros/plugins/modules/api.py\", line 573, in main\n File \"/var/folders/p2/xtr9ql715bd78nvs0v71x25m0000gn/T/ansible_community.routeros.api_payload_n8r02h0l/ansible_community.routeros.api_payload.zip/ansible_collections/community/routeros/plugins/modules/api.py\", line 365, in __init__\n File \"/var/folders/p2/xtr9ql715bd78nvs0v71x25m0000gn/T/ansible_community.routeros.api_payload_n8r02h0l/ansible_community.routeros.api_payload.zip/ansible_collections/community/routeros/plugins/modules/api.py\", line 547, in api_arbitrary\n File \"/var/folders/p2/xtr9ql715bd78nvs0v71x25m0000gn/T/ansible_community.routeros.api_payload_n8r02h0l/ansible_community.routeros.api_payload.zip/ansible_collections/community/routeros/plugins/modules/api.py\", line 414, in list_to_dic\n File \"/var/folders/p2/xtr9ql715bd78nvs0v71x25m0000gn/T/ansible_community.routeros.api_payload_n8r02h0l/ansible_community.routeros.api_payload.zip/ansible_collections/community/routeros/plugins/module_utils/quoting.py\", line 201, in convert_list_to_dictionary\nansible_collections.community.routeros.plugins.module_utils.quoting.ParseError: missing '=' after 'id_rsa.pub.txt'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
I think this is a bug .. If I not mistake there is a check for .id and the code mistake it with id_rsa.pub.txt Will double check and will try to fix it
I think this is a bug .. If I not mistake there is a check for .id and the code mistake it with id_rsa.pub.txt Will double check and will try to fix it
Ou sorry my mistake, actually this is related to something else .. not a code issue .. after cmd 1st arg .. for any other '=' is mandatory ..related to to ros API it self .. will check for solution how this can be structure properly
cmd: 'set id_rsa.pub.txt contents="{{ ssh_pub_key }}"'
Hi,
Using 'numbers=' can solve your problem .. as general almost everything in ROS is key=value pair
@gray380 please test it in this way
/file set numbers=id_rsa.pub.txt contents="test"
- name: Put content to the ssh pub key
community.routeros.api:
path: "file"
cmd: 'set numbers=id_rsa.pub.txt contents="{{ ssh_pub_key }}"'
Let me know if this work for you Regards