ansible-collections / cisco.nxos

Ansible Network Collection for Cisco NXOS
GNU General Public License v3.0
116 stars 109 forks source link

Cisco.nxos command module search for `show inventory` instead on `show version` in Ansible Core 2.15 #729

Closed abhishgu closed 9 months ago

abhishgu commented 1 year ago
SUMMARY
    Error Code while running the playbook from Ansible core 2.15:
    fatal: [host]: FAILED! => {
        "changed": false,
    "module_stderr": "show inventory\\r\\r\\nError: Invalid argument 'inventory '. Please check syntax in command reference g\\r\\nuide\\r\\n\\u001b[1m\\u001b[7m%\\u001b[27m\\u001b[1m\\u001b[0m                                                                               \\r \\r\\r\\u001b[0m\\u001b[27m\\u001b[24m\\u001b[JLN1AGL05-NPCA001lab# \\u001b[K",
        "module_stdout": "",
        "msg": "MODULE FAILURE\\nSee stdout/stderr for the exact error"
    }
ISSUE TYPE
COLLECTION VERSION

Latest 5.1.0 cisco.nxos collection version.

STEPS TO REPRODUCE
 nxos_command:
        commands:
        - show version
      register: "output"
ACTUAL RESULTS
TASK [Get ACI border/service leaf switches] ************************************
task path: /runner/project/get_npc_topo.yaml:10
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
Loading collection ansible.netcommon from /usr/share/ansible/collections/ansible_collections/ansible/netcommon
Loading collection ansible.utils from /usr/share/ansible/collections/ansible_collections/ansible/utils
redirecting (type: terminal) ansible.builtin.nxos to cisco.nxos.nxos
redirecting (type: cliconf) ansible.builtin.nxos to cisco.nxos.nxos
<xxxxxx> attempting to start connection
<xxxxxx> using connection plugin ansible.netcommon.network_cli
Found ansible-connection at path /usr/bin/ansible-connection
<xxxxxx> local domain socket does not exist, starting it
<xxxxxx> control socket path is /home/runner/.ansible/pc/69a9716cfc
<xxxxxx> Loading collection ansible.builtin from 
<xxxxxx> redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
<xxxxxx> Loading collection ansible.netcommon from /usr/share/ansible/collections/ansible_collections/ansible/netcommon
<xxxxxx> Loading collection ansible.utils from /usr/share/ansible/collections/ansible_collections/ansible/utils
<xxxxxx> redirecting (type: terminal) ansible.builtin.nxos to cisco.nxos.nxos
<xxxxxx> Loading collection cisco.nxos from /usr/share/ansible/collections/ansible_collections/cisco/nxos
<xxxxxx> redirecting (type: cliconf) ansible.builtin.nxos to cisco.nxos.nxos
<xxxxxx> local domain socket listeners started successfully
<xxxxxx> loaded cliconf plugin ansible_collections.cisco.nxos.plugins.cliconf.nxos from path /usr/share/ansible/collections/ansible_collections/cisco/nxos/plugins/cliconf/nxos.py for network_os nxos
<xxxxxx> ssh type is set to auto
<xxxxxx> autodetecting ssh_type
<xxxxxx> ssh type is now set to libssh
<xxxxxx> Loading collection ansible.builtin from 
<xxxxxx> local domain socket path is /home/runner/.ansible/pc/69a9716cfc
redirecting (type: modules) ansible.builtin.nxos_command to cisco.nxos.nxos_command
redirecting (type: action) ansible.builtin.nxos to cisco.nxos.nxos
<xxxxxx> Using network group action nxos for nxos_command
redirecting (type: action) ansible.builtin.nxos to cisco.nxos.nxos
<xxxxxx> ANSIBLE_NETWORK_IMPORT_MODULES: enabled
redirecting (type: modules) ansible.builtin.nxos_command to cisco.nxos.nxos_command
<xxxxxx> ANSIBLE_NETWORK_IMPORT_MODULES: found nxos_command  at /usr/share/ansible/collections/ansible_collections/cisco/nxos/plugins/modules/nxos_command.py
<xxxxxx> ANSIBLE_NETWORK_IMPORT_MODULES: running nxos_command
<xxxxxx> ANSIBLE_NETWORK_IMPORT_MODULES: complete
fatal: [xxxxxx]: FAILED! => {
    "changed": false,
    "module_stderr": "show inventory\\r\\r\\nError: Invalid argument 'inventory '. Please check syntax in command reference g\\r\\nuide\\r\\n\\u001b[1m\\u001b[7m%\\u001b[27m\\u001b[1m\\u001b[0m                                                                               \\r \\r\\r\\u001b[0m\\u001b[27m\\u001b[24m\\u001b[JLN1AGL05-NPCA001lab# \\u001b[K",
    "module_stdout": "",
    "msg": "MODULE FAILURE\\nSee stdout/stderr for the exact error"
}
EXPECTED RESULTS

It should register show inventory outcome in Ansible core 2.15.

NilashishC commented 1 year ago

@abhishgu Could you please share the following with us to debug this further?

As a side note, the commands show version and show inventory are always run by the NX-OS Ansible CLICONF plugin when interacting with a Cisco Nexus appliance to gather metadata that is later used by modules mentioned in the play. These commands are known to work with a variety of Nexus 3k, 7k, 9k that we have tested our modules with and have been a part of the CLICONF plugin for at least 6 years (ansible 2.5.0+). It is surprising why the device CLI reports that the show inventory command is invalid in your case. Are you sure that the target appliances are Nexus switches?

Thank you.

carlobongiovanni commented 9 months ago

hi @NilashishC , I can reproduce it with cisco apic devices. II have this ansible:

$ ansible --version
ansible [core 2.14.9]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/carlo.bongiovanni/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/carlo.bongiovanni/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.18 (main, Sep  7 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

I have cisco nxos galaxy collection, version 6.0.0.

My task fails with FAILED! => {"changed": false, "module_stderr": "show inventory\r\r\nError: Invalid argument 'inventory '. Please check syntax in command reference g\r\nuide\r\n\u001b[1m\u001b[7m%\u001b[27m\u001b[1m\u001b[0m \r \r\r\u001b[0m\u001b[27m\u001b[24m\u001b[Jid12ms-apic3# \u001b[K", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error"}

here you find the ansible.log, created from device interaction logs: ansible.log

And my play is very easy:

- name: Execute commands on network devices
  hosts: all
  gather_facts: false
  tasks:
  - name: "Run the NXOS command"
    cisco.nxos.nxos_command:
      commands:
        - command: show version
          output: json
    vars:
      ansible_persistent_log_messages: True

can you provide a fix?

Thanks C.

NilashishC commented 9 months ago

@carlobongiovanni As explained in my previous comment, the commands show version and show inventory are always run by the NX-OS Ansible CLICONF plugin when interacting with a Cisco Nexus appliance to gather metadata that is later used by modules mentioned in the play.

This collection is compatible only with Cisco Nexus switches in NX-OS mode (and partially compatible with NX-OS on Cisco MDS). From the traceback you shared, show inventory does not seem to be valid in APIC/ACI mode and hence, it's not working.

carlobongiovanni commented 9 months ago

hi @NilashishC , thanks for your answer, now I understand the issue. From my point of view the command function should just help to execute a command, and should not hide the execution of other commands. Or at least it should be possible to disable such a behaviour. But ok, I now understand I was using the wrong ansible collection for my network appliance. Thanks for your answer. I believe the issue can be closed.

NilashishC commented 9 months ago

@abhishgu Since there's no activity on this issue, I'll be closing it for now. Please feel free to re-open this or create a new ticket, if you'd like to take this further.

Thank you.