'Ansible - Cisco NX-OS unable to determine device OS

I'm a newbie on Ansible and I am trying to extract some typical show output from Cisco Nexus devices using the Ansible cisco.nxos modules.

I am using the cisco.nxos.nxos_command module within the playbook to run show version on the NX-OS devices. However, I am getting the following error upon playbook execution:

fatal: [Nx-01]: FAILED! =>
  msg: Unable to automatically determine host network os. Please manually configure ansible_network_os value for this host

However, I am specifying the OS type in the inventory file:

[nxos]
Nx-01

[nxos:vars]
ansible_connection=ansible.netcommon.network_cli
**ansible_network_os=cisco.nxos.nxos**
ansible_user=testuser
ansible_ssh_pass=test

Here is the playbook I am using:

---
- name: show version
  hosts: nxos
  gather_facts: false

  tasks:
    - name: show version
      cisco.nxos.nxos_command:
        commands: show version
      register: output

    -  debug: var=output.stdout_lines

Am I missing something? The exact same setup works perfectly for Cisco IOS when used with cisco.ios module.



Solution 1:[1]

According the error message the a variable value is missing, ansible_network_os: cisco.nxos.nxos. In a test the following main.yaml was working properly.

- hosts: nxos
  gather_facts: false

  # Prepare execution environment
  # Doc: https://docs.ansible.com/ansible/latest/network/user_guide/platform_nxos.html

  vars:
    ansible_connection: ansible.netcommon.network_cli
    ansible_network_os: cisco.nxos.nxos
    ansible_become: yes
    ansible_become_method: enable
    ansible_user: testuser
    ansible_password: ********

  tasks:

    # Usage of command module
    # Doc: https://docs.ansible.com/ansible/latest/collections/cisco/nxos/nxos_command_module.html
  
    - name: Run command on remote device
      cisco.nxos.nxos_command:
        commands: show version
      register: results

    - name: Show results
      debug:
        msg: "{{ results.stdout_lines }}"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1