首页 > 解决方案 > Cisco Nexus 的 Ansible 手册因提供商中的 nxapi 而失败

问题描述

我无法让这本剧本发挥作用。我正在尝试使用“nxapi”提供程序方法。我在目标设备上设置了 nxapi。我有一个包含以下设置的 group_vars 文件:

ansible_connection: local
ansible_network_os: nxos
ansible_user: user
ansible_password: password

剧本代码是:

- name: nxos_facts module
  hosts: "{{ myhosts }}"
  vars:
    ssh:
      host: "{{ myhosts }}"
      username: "{{ ansible_user }}"
      password: "{{ ansible_password }}"
      transport: cli
    nxapi:
      host: "{{ myhosts }}"
      username: "{{ ansible_user }}"
      password: "{{ ansible_password }}"
      transport: nxapi
      use_ssl: yes
      validate_certs: no
      port: 8443

  tasks:


    - name: nxos_facts nxapi
      nxos_facts:
        provider: "{{ nxapi }}"

When I debug the failed playbook, I see this line:
 ESTABLISH LOCAL CONNECTION FOR USER: < MY USER  NAME >

It seems like the Playbook is not using the variables in the group_vars file , which specify a specific user to connect to the nxapi service on the switch.

标签: ansiblenexuscisco

解决方案


由于缺少代表,无法添加评论

确保您的 group_vars 与主机文件中的子组匹配。(不能从你的问题中看出)

主机文件:

all:
  hosts:
    SWITCH1:
      ansible_host: 192.168.1.1
  children:
    group1:
      hosts:
        SWITCH1:

然后,您可以将 Group 变量放在 2 个文件之一中,all.ymlgroup1.yml


推荐阅读