ansible-collections / ansible.netcommon

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

ansible.netcommon.cli_command module should consider the task successful if launched command succeed to execute even though the output includes error keyword. #615

Open Akasurde opened 9 months ago

Akasurde commented 9 months ago

Summary

If the launched command includes the specific keywords like syntax error, ansible.netcommon.cli_command module regards the task status as failed even though the launched command itself succeed to execute.

Issue Type

ansible.netcommon.cli_command

Component Name

netcommon

Ansible Version

$ ansible --version
ansible-core 2.15.2

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = /etc/ansible/ansible.cfg

OS / Environment

RHEL 8

Steps to Reproduce

In this case, I have confirmed the issue with Juniper request support information command.

- name: Testing copy software
  hosts: "{{ target }}"

  tasks:
    - name: run show version on remote devices
      junipernetworks.junos.junos_command:
        commands: "request support information"

Run the above playbook towards the managed node Junos. As you can see in the execution logs below, the show services advanced-anti-malware command is launched by the request support information command in Junos, but it fails due to a syntax error. While this is likely a bug in Junos, the request support information command itself succeeds, so I believe the Ansible task should be considered successful.

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

The task status is regarded as failed.

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.


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct
Akasurde commented 9 months ago

cc @mahoutukaisali