ansible-collections / junipernetworks.junos

Ansible Network Collection for Juniper JunOS
GNU General Public License v3.0
84 stars 63 forks source link

junipernetworks.junos.junos_command should consider the task successful if launched command succeed to execute even though the output includes error keyword. #481

Open mahoutukaisali opened 10 months ago

mahoutukaisali commented 10 months ago
SUMMARY

junipernetworks.junos.junos_command module regards the task status as "failed" when request support information command output includes specific keywords like syntax error.

ISSUE TYPE
COMPONENT NAME

junipernetworks.junos.junos_command

ANSIBLE VERSION
ansible-core 2.15.2
COLLECTION VERSION
junipernetworks.junos: 5.1.0
STEPS TO REPRODUCE
- name: Testing copy software
  hosts: "{{ target }}"

  tasks:
    - name: run show version on remote devices
      junipernetworks.junos.junos_command:
        commands: "request support information"
TASK [run show version on remote devices] **************************************
task path: /path/to/juniper_rsi_junos_command.yml:10
The full traceback is:
  File "/usr/share/ansible/collections/ansible_collections/junipernetworks/junos/plugins/modules/junos_command.py", line 404, in main
    output.append(conn.get(command=cmd))
  File "/usr/local/lib/python3.9/site-packages/ansible/module_utils/connection.py", line 200, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
[WARNING]: arguments wait_for, match, rpcs are not supported when using
transport=cli
fatal: [EXAMPLE.HOST.COM]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "commands": [
                "request support information
            ],
            "display": null,
            "interval": 1,
            "match": "all",
            "retries": 10,
            "rpcs": null,
            "wait_for": null
        }
    },
    "msg":

(...)

show services advanced-anti-malware statistics\r\n\r\n\r\nerror: syntax error, expecting <command>: advanced-anti-malware\r\n\r\n{master}\r\nUSER@EXAMPLE.HOST.COM> "

PLAY RECAP *********************************************************************
USER@EXAMPLE.HOST.COM : ok=0    changed=0    unreachable=0   failed=1   skipped=0    rescued=0    ignored=0   
Please review the log for errors.
EXPECTED RESULTS
ACTUAL RESULTS
rohitthakur2590 commented 7 months ago

@mahoutukaisali , We could not reproduce this , is it possible for you to share the CLI command output?

request support information

ldacol commented 5 days ago

@rohitthakur2590 , I originally opened the case through RH support. Unfortunately I am unable to share the full "request support information" publicly due to sensitive information, however the issue may originate from the command returning the "error" keyword which is caught by the ansible module as an error hence exit.

Please try to run the junos_command with a command that returns error and validate the output. I have noticed that in the last year the collection version has been updated considerably. We are planning to move to a newer versions, however this is not planned for the current quarter.

An example of a cli command

root@labrt-RE4> show services nat mappings summary
root@labrt-RE4> show services nat pool
root@labrt-RE4> show services nat pool detail
root@labrt-RE4> show services advanced-anti-malware status
error: syntax error, expecting <command>: advanced-anti-malware
root@labrt-RE4> show services advanced-anti-malware statistics
error: syntax error, expecting <command>: advanced-anti-malware
{master}