ansible-aci
ansible-aci copied to clipboard
aci_rest: No JSON object could not be decoded error
SUMMARY
aci_rest module does not seem to work when xml file is specified in src parameter.
Affected Module Name(s):
aci_rest
Collection versions
- cisco.aci v1.0.1 later
ANSIBLE VERSION
ansible --version ansible [core 2.11.11.post0] config file = /runner/project/ansible.cfg configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.8/site-packages/ansible ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections executable location = /usr/local/bin/ansible python version = 3.8.12 (default, Sep 21 2021, 00:10:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] jinja version = 3.1.2 libyaml = True
CONFIGURATION
DEFAULT_MODULE_PATH(/etc/ansible/ansible.cfg) = [u'/usr/share/ansible']
OS / ENVIRONMENT
N/A
DESCRIPTION:
I have checked the problem and found that there may be unnecessary code in line 382 of aci_rest.py. https://github.com/CiscoDevNet/ansible-aci/blob/master/plugins/modules/aci_rest.py#L382
The src file has a branch in rest_type that allows content to be loaded in either json or xml format, but for some reason json.loads is being executed before the branch. Is my understands correct ?
Output/ Error message
The full traceback is:
Traceback (most recent call last):
File "/root/.ansible/tmp/ansible-tmp-1654215599.9376042-118-106740548368113/AnsiballZ_aci_rest.py", line 100, in <module>
_ansiballz_main()
File "/root/.ansible/tmp/ansible-tmp-1654215599.9376042-118-106740548368113/AnsiballZ_aci_rest.py", line 92, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/root/.ansible/tmp/ansible-tmp-1654215599.9376042-118-106740548368113/AnsiballZ_aci_rest.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible_collections.cisco.aci.plugins.modules.aci_rest', init_globals=dict(_module_fqn='ansible_collections.cisco.aci.plugins.modules.aci_rest', _modlib_path=modlib_path),
File "/usr/lib64/python3.8/runpy.py", line 207, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.8/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib64/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/tmp/ansible_aci_rest_payload_f_19tas6/ansible_aci_rest_payload.zip/ansible_collections/cisco/aci/plugins/modules/aci_rest.py", line 451, in <module>
File "/tmp/ansible_aci_rest_payload_f_19tas6/ansible_aci_rest_payload.zip/ansible_collections/cisco/aci/plugins/modules/aci_rest.py", line 376, in main
File "/usr/lib64/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
STEPS TO REPRODUCE
JSONDecodeError occurs when xml file is specified in src when using aci_rest module.
- name: xml file push using Ansible aci_rest module
aci_rest:
host: '{{ aci_endpoint }}'
username: '{{ aci_user }}'
password: '{{ aci_pass }}'
validate_certs: False
method: post
path: /api/mo/uni.xml
src: "sample.xml"
Expected Behavior
The object would be added to the APIC.
TASK [xmlpush : xml file push using Ansible aci_rest module] ****************************************************************
ok: [localhost -> localhost] => (item=sample.xml)
PLAY RECAP ******************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Actual Behavior
The full traceback is:
Traceback (most recent call last):
File "/root/.ansible/tmp/ansible-tmp-1654215599.9376042-118-106740548368113/AnsiballZ_aci_rest.py", line 100, in <module>
_ansiballz_main()
File "/root/.ansible/tmp/ansible-tmp-1654215599.9376042-118-106740548368113/AnsiballZ_aci_rest.py", line 92, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/root/.ansible/tmp/ansible-tmp-1654215599.9376042-118-106740548368113/AnsiballZ_aci_rest.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible_collections.cisco.aci.plugins.modules.aci_rest', init_globals=dict(_module_fqn='ansible_collections.cisco.aci.plugins.modules.aci_rest', _modlib_path=modlib_path),
File "/usr/lib64/python3.8/runpy.py", line 207, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.8/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib64/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/tmp/ansible_aci_rest_payload_f_19tas6/ansible_aci_rest_payload.zip/ansible_collections/cisco/aci/plugins/modules/aci_rest.py", line 451, in <module>
File "/tmp/ansible_aci_rest_payload_f_19tas6/ansible_aci_rest_payload.zip/ansible_collections/cisco/aci/plugins/modules/aci_rest.py", line 376, in main
File "/usr/lib64/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
failed: [localhost -> localhost] (item=sample.xml) => {
"changed": false,
"item": "sample.xml",
"module_stderr": "Traceback (most recent call last):\n File \"/root/.ansible/tmp/ansible-tmp-1654215599.9376042-118-106740548368113/AnsiballZ_aci_rest.py\", line 100, in <module>\n _ansiballz_main()\n File \"/root/.ansible/tmp/ansible-tmp-1654215599.9376042-118-106740548368113/AnsiballZ_aci_rest.py\", line 92, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/root/.ansible/tmp/ansible-tmp-1654215599.9376042-118-106740548368113/AnsiballZ_aci_rest.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible_collections.cisco.aci.plugins.modules.aci_rest', init_globals=dict(_module_fqn='ansible_collections.cisco.aci.plugins.modules.aci_rest', _modlib_path=modlib_path),\n File \"/usr/lib64/python3.8/runpy.py\", line 207, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib64/python3.8/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/lib64/python3.8/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_aci_rest_payload_f_19tas6/ansible_aci_rest_payload.zip/ansible_collections/cisco/aci/plugins/modules/aci_rest.py\", line 451, in <module>\n File \"/tmp/ansible_aci_rest_payload_f_19tas6/ansible_aci_rest_payload.zip/ansible_collections/cisco/aci/plugins/modules/aci_rest.py\", line 376, in main\n File \"/usr/lib64/python3.8/json/__init__.py\", line 357, in loads\n return _default_decoder.decode(s)\n File \"/usr/lib64/python3.8/json/decoder.py\", line 337, in decode\n obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n File \"/usr/lib64/python3.8/json/decoder.py\", line 355, in raw_decode\n raise JSONDecodeError(\"Expecting value\", s, err.value) from None\njson.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}