ansible-collections / ansible.netcommon

Ansible Network Collection for Common Code
GNU General Public License v3.0
143 stars 102 forks source link

netconf_rpc fails with traceback #158

Open elajoie opened 3 years ago

elajoie commented 3 years ago
SUMMARY

When running a play such as the play below we receive a traceback. ` - name: Get vfabric ID netconf_rpc: display: xml rpc: get content: |

{{fabric}}
register: list

`

ISSUE TYPE
COMPONENT NAME

netconf_rpc

ANSIBLE VERSION
ansible --version
CONFIGURATION
ansible 2.9.7
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Dec  5 2019, 15:45:45) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
OS / ENVIRONMENT

RHEL8 VM on KVM

STEPS TO REPRODUCE

Run the playbook

---
  - name: Get vfabric ID 
    netconf_rpc:
      display: xml
      rpc: get 
      content: | 
        <filter type="subtree"> 
         <Fabric xmlns="urn:vendor:faas:fabrics">
          <FabricID>{{fabric}}</FabricID>
            <Node>
              <NodeID/>
              <Name/>
            </Node>
          </Fabric>
        </filter>
    register: list

  - name: debug 
    debug: 
     msg: " {{list}} " 
  - name: Parse xml 
    xml:
     xmlstring: "{{ list.output }}"
     xpath: "/data/Fabric/Node[Name='{{item.name}}']/NodeID"
     content: text
    register: result 

  - name: Extract node-id
    set_fact:
      nodeID: "{{ result['matches'][0]['NodeID'] }}"

  - name: rename TP 
    debug: 
     msg: "Fabric: {{fabric}} - Leaf: {{item.name}} - ID: {{nodeID}} " 
EXPECTED RESULTS

That the get command should work and return contents

ACTUAL RESULTS

image

{
    "module_stdout": "",
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/connection.py\", line 156, in _exec_jsonrpc\n  File \"/usr/lib64/python3.6/json/__init__.py\", line 354, in loads\n    return _default_decoder.decode(s)\n  File \"/usr/lib64/python3.6/json/decoder.py\", line 339, in decode\n    obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n  File \"/usr/lib64/python3.6/json/decoder.py\", line 357, 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\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/var/lib/awx/.ansible/tmp/ansible-local-2tq6u897x/ansible-tmp-1602699898.397022-92-145463566026323/AnsiballZ_netconf_rpc.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/var/lib/awx/.ansible/tmp/ansible-local-2tq6u897x/ansible-tmp-1602699898.397022-92-145463566026323/AnsiballZ_netconf_rpc.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/var/lib/awx/.ansible/tmp/ansible-local-2tq6u897x/ansible-tmp-1602699898.397022-92-145463566026323/AnsiballZ_netconf_rpc.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.network.netconf.netconf_rpc', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/modules/network/netconf/netconf_rpc.py\", line 264, in <module>\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/modules/network/netconf/netconf_rpc.py\", line 240, in main\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/network/netconf/netconf.py\", line 119, in dispatch\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/network/netconf/netconf.py\", line 41, in get_connection\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/network/netconf/netconf.py\", line 55, in get_capabilities\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/connection.py\", line 179, in __rpc__\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/connection.py\", line 161, in _exec_jsonrpc\nansible.module_utils.connection.ConnectionError: Unable to decode JSON from response to get_capabilities(). Received 'None'.\n",
    "exception": "Traceback (most recent call last):\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/connection.py\", line 156, in _exec_jsonrpc\n  File \"/usr/lib64/python3.6/json/__init__.py\", line 354, in loads\n    return _default_decoder.decode(s)\n  File \"/usr/lib64/python3.6/json/decoder.py\", line 339, in decode\n    obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n  File \"/usr/lib64/python3.6/json/decoder.py\", line 357, 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\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/var/lib/awx/.ansible/tmp/ansible-local-2tq6u897x/ansible-tmp-1602699898.397022-92-145463566026323/AnsiballZ_netconf_rpc.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/var/lib/awx/.ansible/tmp/ansible-local-2tq6u897x/ansible-tmp-1602699898.397022-92-145463566026323/AnsiballZ_netconf_rpc.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/var/lib/awx/.ansible/tmp/ansible-local-2tq6u897x/ansible-tmp-1602699898.397022-92-145463566026323/AnsiballZ_netconf_rpc.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.network.netconf.netconf_rpc', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/modules/network/netconf/netconf_rpc.py\", line 264, in <module>\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/modules/network/netconf/netconf_rpc.py\", line 240, in main\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/network/netconf/netconf.py\", line 119, in dispatch\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/network/netconf/netconf.py\", line 41, in get_connection\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/network/netconf/netconf.py\", line 55, in get_capabilities\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/connection.py\", line 179, in __rpc__\n  File \"/tmp/ansible_netconf_rpc_payload_e8tllabr/ansible_netconf_rpc_payload.zip/ansible/module_utils/connection.py\", line 161, in _exec_jsonrpc\nansible.module_utils.connection.ConnectionError: Unable to decode JSON from response to get_capabilities(). Received 'None'.\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1,
    "_ansible_no_log": false,
    "changed": false
}
elajoie commented 3 years ago

This is fixed in 2.10.7 once ncclient is also added to the vENV