Juniper / ansible-junos-stdlib

Junos modules for Ansible
Apache License 2.0
302 stars 156 forks source link

juniper.device.config does not transmit the error message with juniper.device.pyez connection #668

Open slefol opened 3 months ago

slefol commented 3 months ago

Issue Type

Module Name

juniper.device.config

juniper.device collection and Python libraries version

$ ansible --version
ansible [core 2.17.0]
  config file = /home/ansible/ansible_network/ansible.cfg
  configured module search path = ['/home/slefol/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/slefol/ansible-venv/lib/python3.11/site-packages/ansible
  ansible collection location = /home/slefol/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/slefol/ansible-venv/bin/ansible
  python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/home/slefol/ansible-venv/bin/python3)
  jinja version = 3.1.3
  libyaml = True

$ ansible-galaxy collection list
Collection     Version
-------------- -------
ansible.netcommon     6.1.1
ansible.posix         1.5.4
ansible.utils         3.0.0
community.general     8.6.0
juniper.device        1.0.4

$ pip freeze
ansible-core==2.17.0
ansible-pylibssh==1.1.0
jsnapy==1.3.7
junos-eznc==2.7.1
ncclient==0.6.15
netmiko==4.3.0
paramiko==3.4.0
...

OS / Environment

QFX5100 17.3R3-S4.2

Summary

Running juniper.device.config with juniper.device.pyez as connection type does not transmit the error message when configuration is bad. connection: local works as expected.

Steps to reproduce

---
- name: Test juniper. device.config module
  hosts: all
  gather_facts: no
  collections:
    - juniper.device

  tasks:
    - name: "Execute set configuration"
      config:
        load: "set"
        format: "set"
        lines: 'delete system login message'
        comment: "test"

Expected results

TASK [Execute set configuration] *************************************************************************************************************************************************************************
fatal: [sw0-dc.artem]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/home/slefol/ansible-venv/bin/python3.11"}, "changed": false, "msg": "Failure loading the configuraton: ConfigLoadError(severity: warning, bad_element: None, message: warning: statement not found: login)"}

Actual results

TASK [Execute set configuration] *************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.module_utils.connection.ConnectionError: 'Connection' object has no attribute 'pyez_exception'
fatal: [sw0-dc.artem]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/slefol/.ansible/tmp/ansible-local-851993dvp7usn/ansible-tmp-1716295990.181573-85202-163164558317835/AnsiballZ_config.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/slefol/.ansible/tmp/ansible-local-851993dvp7usn/ansible-tmp-1716295990.181573-85202-163164558317835/AnsiballZ_config.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/slefol/.ansible/tmp/ansible-local-851993dvp7usn/ansible-tmp-1716295990.181573-85202-163164558317835/AnsiballZ_config.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.config', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.config', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_config_payload_nup0t6n5/ansible_config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1252, in <module>\n  File \"/tmp/ansible_config_payload_nup0t6n5/ansible_config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 1146, in main\n  File \"/tmp/ansible_config_payload_nup0t6n5/ansible_config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1512, in load_configuration\n  File \"/tmp/ansible_config_payload_nup0t6n5/ansible_config_payload.zip/ansible/module_utils/connection.py\", line 199, in __rpc__\nansible.module_utils.connection.ConnectionError: 'Connection' object has no attribute 'pyez_exception'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

instead of having the error message "Failure loading the configuraton: ConfigLoadError(severity: warning, bad_element: None, message: warning: statement not found: login)", the task returns "'Connection' object has no attribute 'pyez_exception'".

juniper.device.command with juniper.device.pyez works as expected.

---
- name: Test juniper. device.config module
  hosts: all
  gather_facts: no
  collections:
    - juniper.device

  tasks:
    - name: Get uptime
      juniper.device.command:
        commands: "show system uptime2"
TASK [Get uptime] ****************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.module_utils.connection.ConnectionError: RpcError(severity: error, bad_element: uptime2, message: syntax error, expecting <command>)
fatal: [sw0-dc.artem]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/slefol/.ansible/tmp/ansible-local-86194ok9prres/ansible-tmp-1716296773.1521301-86197-64237631605524/AnsiballZ_command.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/slefol/.ansible/tmp/ansible-local-86194ok9prres/ansible-tmp-1716296773.1521301-86197-64237631605524/AnsiballZ_command.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/slefol/.ansible/tmp/ansible-local-86194ok9prres/ansible-tmp-1716296773.1521301-86197-64237631605524/AnsiballZ_command.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.command', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.command', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_juniper.device.command_payload_07orv17r/ansible_juniper.device.command_payload.zip/ansible_collections/juniper/device/plugins/modules/command.py\", line 493, in <module>\n  File \"/tmp/ansible_juniper.device.command_payload_07orv17r/ansible_juniper.device.command_payload.zip/ansible_collections/juniper/device/plugins/modules/command.py\", line 406, in main\n  File \"/tmp/ansible_juniper.device.command_payload_07orv17r/ansible_juniper.device.command_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 1780, in get_rpc\n  File \"/tmp/ansible_juniper.device.command_payload_07orv17r/ansible_juniper.device.command_payload.zip/ansible/module_utils/connection.py\", line 199, in __rpc__\nansible.module_utils.connection.ConnectionError: RpcError(severity: error, bad_element: uptime2, message: syntax error, expecting <command>)\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

We can see "RpcError(severity: error, bad_element: uptime2, message: syntax error, expecting )"

slefol commented 1 month ago

Hi @dineshbaburam91, are there any updates fot this issue ? Please keep me updated about the progress.

dineshbaburam91 commented 1 month ago

Let me check and get back to you.