【问题标题】:Ansible - Cisco NX-OS unable to determine device OSAnsible - Cisco NX-OS 无法确定设备操作系统
【发布时间】:2023-06-27 08:53:01
【问题描述】:

我是 Ansible 的新手,我正在尝试使用 Ansible cisco.nxos 模块从 Cisco Nexus 设备中提取一些典型的显示输出。

我正在使用 playbook 中的 cisco.nxos.nxos_command 模块在 NX-OS 设备上运行 show version。但是,我在 playbook 执行时收到以下错误:

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

但是,我在清单文件中指定操作系统类型:

[nxos]
Nx-01

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

这是我正在使用的剧本:

---
- 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

我错过了什么吗?当与cisco.ios 模块一起使用时,完全相同的设置非常适用于 Cisco IOS。

【问题讨论】:

    标签: ansible cisco ansible-inventory


    【解决方案1】:

    根据错误消息,缺少变量值ansible_network_os: cisco.nxos.nxos。在测试中,以下main.yaml 工作正常。

    - 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 }}"
    

    【讨论】:

      最近更新 更多