Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Jan 11, 2024 · 1 comment

Comments

@Akasurde
Copy link
Member

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\[email protected]> "

PLAY RECAP *********************************************************************
[email protected] : ok=0    changed=0    unreachable=0   failed=1   skipped=0    rescued=0    ignored=0   
Please review the log for errors.

Expected Results

  • The task should be considered successful since the execution of the request support information command itself is successful.

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\[email protected]> "

PLAY RECAP *********************************************************************
[email protected] : 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant