Juniper / ansible-junos-stdlib

Junos modules for Ansible
Apache License 2.0
305 stars 158 forks source link

Ansible RPC error with junipe.device.rpc module #622

Closed aravindhananbarasu closed 6 months ago

aravindhananbarasu commented 1 year ago

When performing RPC calls that return a value of type boolean, we are seeing an error being returned. This only happens if the connection type is using pyez which is persistent.

We are using the below variables: [juniper:vars] ansible_connection=juniper.device.pyez ansible_network_os=juniper.device.junos >>>> We didn’t get any issues when we were using Juniper.junos here. But we are using juniper.device as it’s depreciated.

An example of a play is shown below:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.module_utils.connection.ConnectionError: Type 'bool' cannot be serialized. fatal: [test301-rtr-6]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/home/ext.paul.herbert/.ansible/tmp/ansible-local-1408nir1vvrb/ansible-tmp-1684838319.1980417-1522-87497565430803/AnsiballZ_rpc.py\", line 107, in \n _ansiballz_main()\n File \"/home/ext.paul.herbert/.ansible/tmp/ansible-local-1408nir1vvrb/ansible-tmp-1684838319.1980417-1522-87497565430803/AnsiballZ_rpc.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/ext.paul.herbert/.ansible/tmp/ansible-local-1408nir1vvrb/ansible-tmp-1684838319.1980417-1522-87497565430803/AnsiballZ_rpc.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.rpc', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.rpc', _modlib_path=modlib_path),\n File \"/usr/lib/python3.8/runpy.py\", line 205, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib/python3.8/runpy.py\", line 95, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/lib/python3.8/runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_juniper.device.rpc_payload_3e8q3l8g/ansible_juniper.device.rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 636, in \n File \"/tmp/ansible_juniper.device.rpc_payload_3e8q3l8g/ansible_juniper.device.rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 556, in main\n File \"/tmp/ansible_juniper.device.rpc_payload_3e8q3l8g/ansible_juniper.device.rpc_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1719, in get_rpc\n File \"/tmp/ansible_juniper.device.rpc_payload_3e8q3l8g/ansible_juniper.device.rpc_payload.zip/ansible/module_utils/connection.py\", line 200, in rpc\nansible.module_utils.connection.ConnectionError: Type 'bool' cannot be serialized.\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}


(venv) root@nms5-salt-master-b:~/ansible_galaxy_release_v102_final_test3/ansible-junos-stdlib/tests# vi pb.juniper_junos_rpc.yml

(venv) root@nms5-salt-master-b:~/ansible_galaxy_release_v102_final_test3/ansible-junos-stdlib/tests# ansible-playbook pb.juniper_junos_rpc.yml

PLAY [Test juniper.device.rpc module] *****

TASK [Execute single RPC get-software-information without any kwargs] ***** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.module_utils.connection.ConnectionError: Type 'bool' cannot be serialized. fatal: [test]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/root/.ansible/tmp/ansible-local-5965ors8akzp/ansible-tmp-1687413300.0735672-5970-231951512970846/AnsiballZ_rpc.py\", line 107, in \n _ansiballz_main()\n File \"/root/.ansible/tmp/ansible-local-5965ors8akzp/ansible-tmp-1687413300.0735672-5970-231951512970846/AnsiballZ_rpc.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/root/.ansible/tmp/ansible-local-5965ors8akzp/ansible-tmp-1687413300.0735672-5970-231951512970846/AnsiballZ_rpc.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.rpc', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.rpc', _modlib_path=modlib_path),\n File \"/usr/local/lib/python3.9/runpy.py\", line 210, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/local/lib/python3.9/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/local/lib/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 631, in \n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 551, in main\n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1759, in get_rpc\n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible/module_utils/connection.py\", line 200, in rpc\nansible.module_utils.connection.ConnectionError: Type 'bool' cannot be serialized.\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1} ...ignoring

TASK [Print response] ***** ok: [test] => { "test1": { "changed": false, "exception": "Traceback (most recent call last):\n File \"/root/.ansible/tmp/ansible-local-5965ors8akzp/ansible-tmp-1687413300.0735672-5970-231951512970846/AnsiballZ_rpc.py\", line 107, in \n _ansiballz_main()\n File \"/root/.ansible/tmp/ansible-local-5965ors8akzp/ansible-tmp-1687413300.0735672-5970-231951512970846/AnsiballZ_rpc.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/root/.ansible/tmp/ansible-local-5965ors8akzp/ansible-tmp-1687413300.0735672-5970-231951512970846/AnsiballZ_rpc.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.rpc', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.rpc', _modlib_path=modlib_path),\n File \"/usr/local/lib/python3.9/runpy.py\", line 210, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/local/lib/python3.9/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/local/lib/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 631, in \n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 551, in main\n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1759, in get_rpc\n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible/module_utils/connection.py\", line 200, in rpc\nansible.module_utils.connection.ConnectionError: Type 'bool' cannot be serialized.\n", "failed": true, "module_stderr": "Traceback (most recent call last):\n File \"/root/.ansible/tmp/ansible-local-5965ors8akzp/ansible-tmp-1687413300.0735672-5970-231951512970846/AnsiballZ_rpc.py\", line 107, in \n _ansiballz_main()\n File \"/root/.ansible/tmp/ansible-local-5965ors8akzp/ansible-tmp-1687413300.0735672-5970-231951512970846/AnsiballZ_rpc.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/root/.ansible/tmp/ansible-local-5965ors8akzp/ansible-tmp-1687413300.0735672-5970-231951512970846/AnsiballZ_rpc.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.rpc', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.rpc', _modlib_path=modlib_path),\n File \"/usr/local/lib/python3.9/runpy.py\", line 210, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/local/lib/python3.9/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/local/lib/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 631, in \n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/modules/rpc.py\", line 551, in main\n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1759, in get_rpc\n File \"/tmp/ansible_rpc_payload_pobj_xj7/ansible_rpc_payload.zip/ansible/module_utils/connection.py\", line 200, in rpc\nansible.module_utils.connection.ConnectionError: Type 'bool' cannot be serialized.\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1 } }

PLAY RECAP **** test : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1

(venv) root@nms5-salt-master-b:~/ansible_galaxy_release_v102_final_test3/ansible-junos-stdlib/tests# vi pb.juniper_junos_rpc.yml

(venv) root@nms5-salt-master-b:~/ansible_galaxy_release_v102_final_test3/ansible-junos-stdlib/tests# ansible-playbook pb.juniper_junos_rpc.yml

PLAY [Test juniper.device.rpc module] *****

TASK [Execute single RPC get-software-information without any kwargs] ***** ok: [test]

TASK [Print response] ***** ok: [test] => { "test1": { "attrs": null, "changed": false, "failed": false, "format": "text", "kwargs": { "filename": "messages" }, "msg": "The RPC executed successfully.", "rpc": "clear-log", "stdout": "", "stdout_lines": [] } }

PLAY RECAP **** test : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

dineshbaburam91 commented 9 months ago

Junos software issue, I have raised a ticket for this issue. Let me post once the fix is done.

dineshbaburam91 commented 6 months ago

Junos bug got fixed.

(ansible-env) babud@babud-mbp tests % cat example.yml 
---
- name: Test juniper.device.rpc module
  hosts: all
  gather_facts: no
  collections:
    - juniper.device

  tasks:
#################
    - name: "Execute clear log messages rpc"
      rpc:
        rpcs:
          - "clear-log"
        kwargs:
          - filename: "messages"
        formats: "text"
      register: test1
      tags: [ test1 ]

    - name: Check TEST 1
      debug:
        var: test1

Output:

Validated in both local and PyEZ connection

PLAY [Test juniper.device.rpc module] *******************************************************************************************************************

TASK [Execute clear log messages rpc] *******************************************************************************************************************
ok: [local_connection_testcases]
ok: [pyez_connection_testcases]

TASK [Check TEST 1] *************************************************************************************************************************************
ok: [local_connection_testcases] => {
    "test1": {
        "attrs": null,
        "changed": false,
        "failed": false,
        "format": "text",
        "kwargs": {
            "filename": "messages"
        },
        "msg": "The RPC executed successfully.",
        "rpc": "clear-log",
        "stdout": "\n/var/log/messages cleared successfully\n",
        "stdout_lines": [
            "",
            "/var/log/messages cleared successfully"
        ]
    }
}
ok: [pyez_connection_testcases] => {
    "test1": {
        "attrs": null,
        "changed": false,
        "failed": false,
        "format": "text",
        "kwargs": {
            "filename": "messages"
        },
        "msg": "The RPC executed successfully.",
        "rpc": "clear-log",
        "stdout": "\n/var/log/messages cleared successfully\n",
        "stdout_lines": [
            "",
            "/var/log/messages cleared successfully"
        ]
    }
}