在Ansible中连接NXOS模块时出现问题:列表索引超出范围

在Ansible中连接NXOS模块时出现问题:列表索引超出范围,ansible,network-programming,Ansible,Network Programming,我无法使用Ansible 2.9.13获得一个简单的剧本来对抗Cisco Nexus交换机。我得到一个模糊的索引超出范围错误 这是我的库存文件: [nxos:vars] ansible_user=admin ansible_password=password ansible_network_os=nxos ansible_connection=network_cli ansible_become=yes ansible_become_method=enable ansible_become_pa

我无法使用Ansible 2.9.13获得一个简单的剧本来对抗Cisco Nexus交换机。我得到一个模糊的索引超出范围错误

这是我的库存文件:

[nxos:vars]
ansible_user=admin
ansible_password=password
ansible_network_os=nxos
ansible_connection=network_cli
ansible_become=yes
ansible_become_method=enable
ansible_become_password=password

[nxos]
nxos-sw01 ansible_host=172.23.180.12
这是我的剧本:

---
- name: "nxos configure nxapi"
  hosts: all
  gather_facts: no
  tasks:
  - name: "enble api"
    nxos_nxapi:
      enable_https: yes
执行时,我得到一个关于“列表索引超出范围”的错误,该错误不会产生任何有用的输出:

$ ansible-playbook -i test.inv test.yml -vvvv
ansible-playbook 2.9.0
  config file = /home/some.guy/.ansible.cfg
  configured module search path = [u'/home/some.guy/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/some.guy/.local/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /home/some.guy/.ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /home/some.guy/tmp/ansible/test.inv as it did not pass its verify_file() method
script declined parsing /home/some.guy/tmp/ansible/test.inv as it did not pass its verify_file() method
auto declined parsing /home/some.guy/tmp/ansible/test.inv as it did not pass its verify_file() method
yaml declined parsing /home/some.guy/tmp/ansible/test.inv as it did not pass its verify_file() method
Parsed /home/some.guy/tmp/ansible/test.inv inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /home/some.guy/.local/lib/python2.7/site-packages/ansible/plugins/callback/default.pyc

PLAYBOOK: test.yml **************************************************************************************************************************************************
Positional arguments: test.yml
become_method: sudo
inventory: (u'/home/some.guy/tmp/ansible/test.inv',)
forks: 5
tags: (u'all',)
verbosity: 4
connection: smart
timeout: 10
1 plays in test.yml

PLAY [nxos configure banner] ****************************************************************************************************************************************
META: ran handlers

TASK [enble api] ****************************************************************************************************************************************************
task path: /home/some.guy/tmp/ansible/test.yml:6
<172.23.180.12> attempting to start connection
<172.23.180.12> using connection plugin network_cli
fatal: [nxos-sw01]: FAILED! => {
    "msg": "Traceback (most recent call last):\n  File \"/usr/bin/ansible-connection\", line 342, in <module>\n    main()\n  File \"/usr/bin/ansible-connection\", line 261, in main\n    task_uuid = sys.argv[2]\nIndexError: list index out of range\n"
}

PLAY RECAP **********************************************************************************************************************************************************
nxos-sw01                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
$ansible剧本-i test.inv test.yml-vv
ansible剧本2.9.0
配置文件=/home/some.guy/.ansible.cfg
配置的模块搜索路径=[u'/home/some.guy/.ansible/plugins/modules',u'/usr/share/ansible/plugins/modules']
ansible python模块位置=/home/some.guy/.local/lib/python2.7/site-packages/ansible
可执行文件位置=/usr/bin/ansible playbook
python版本=2.7.5(默认值,2019年8月7日00:51:29)[GCC 4.8.5 20150623(Red Hat 4.8.5-39)]
使用/home/some.guy/.ansible.cfg作为配置文件
设置目录插件
host_list拒绝解析/home/some.guy/tmp/ansible/test.inv,因为它没有通过其verify_file()方法
脚本拒绝解析/home/some.guy/tmp/ansible/test.inv,因为它没有通过其verify_file()方法
自动拒绝解析/home/some.guy/tmp/ansible/test.inv,因为它没有通过其verify_file()方法
yaml拒绝解析/home/some.guy/tmp/ansible/test.inv,因为它没有通过其verify_file()方法
使用ini插件解析/home/some.guy/tmp/ansible/test.inv库存源
正在从/home/some.guy/.local/lib/python2.7/site-packages/ansible/plugins/callback/default.pyc加载默认类型stdout、v2.0的回调插件
剧本:test.yml**************************************************************************************************************************************************
位置参数:test.yml
方法:sudo
库存:(u'/home/some.guy/tmp/ansible/test.inv',)
叉子:5
标签:(u'all',)
冗长:4
连接:智能
超时:10
1在test.yml中播放
播放[nxos配置横幅]****************************************************************************************************************************************
META:ran处理程序
任务[enble api]****************************************************************************************************************************************************
任务路径:/home/some.guy/tmp/ansible/test.yml:6
正在尝试启动连接
使用连接插件网络\u cli
致命:[NXS-sw01]:失败!=>{
“msg:“回溯(最近一次调用):\n文件\“/usr/bin/ansible connection\”,第342行,在\n main()\n文件\“/usr/bin/ansible connection\”,第261行,在main任务中\n uuid=sys.argv[2]\n索引错误:列表索引超出范围\n”
}
重演**********************************************************************************************************************************************************
NXS-sw01:确定=0更改=0无法访问=0失败=1跳过=0获救=0忽略=0
我尝试了不同的NXOS模块,并使用NXAPI连接方法。我似乎什么都做不到。我可以从此服务器手动(SSH)连接到交换机

谁能帮我解决我做错了什么

编辑:这里是对设备运行ansible的尝试。连接信息的解析方式有问题吗?通过运行下面的代码,我完全绕过了我的剧本,仍然会得到相同的错误

$ ansible -vvvv nxos-sw01 -m ping -i test.inv
ansible 2.9.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/etc/ansible/modules', u'/usr/lib/python2.7/site-packages/napalm_ansible']
  ansible python module location = /home/some.guy/.local/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /home/some.guy/tmp/ansible/test.inv as it did not pass its verify_file() method
script declined parsing /home/some.guy/tmp/ansible/test.inv as it did not pass its verify_file() method
auto declined parsing /home/some.guy/tmp/ansible/test.inv as it did not pass its verify_file() method
yaml declined parsing /home/some.guy/tmp/ansible/test.inv as it did not pass its verify_file() method
Parsed /home/some.guy/tmp/ansible/test.inv inventory source with ini plugin
Loading callback plugin minimal of type stdout, v2.0 from /home/some.guy/.local/lib/python2.7/site-packages/ansible/plugins/callback/minimal.pyc
META: ran handlers
<172.23.180.12> attempting to start connection
<172.23.180.12> using connection plugin network_cli
nxos-sw01 | FAILED! => {
    "msg": "Traceback (most recent call last):\n  File \"/usr/bin/ansible-connection\", line 342, in <module>\n    main()\n  File \"/usr/bin/ansible-connection\", line 261, in main\n    task_uuid = sys.argv[2]\nIndexError: list index out of range\n"
$ansible-VVS NXS-sw01-m ping-i test.inv
ansible 2.9.0
配置文件=/etc/ansible/ansible.cfg
配置的模块搜索路径=[u'/etc/ansible/modules',u'/usr/lib/python2.7/site packages/napalm\u ansible']
ansible python模块位置=/home/some.guy/.local/lib/python2.7/site-packages/ansible
可执行文件位置=/usr/bin/ansible
python版本=2.7.5(默认值,2019年8月7日00:51:29)[GCC 4.8.5 20150623(Red Hat 4.8.5-39)]
使用/etc/ansible/ansible.cfg作为配置文件
设置目录插件
host_list拒绝解析/home/some.guy/tmp/ansible/test.inv,因为它没有通过其verify_file()方法
脚本拒绝解析/home/some.guy/tmp/ansible/test.inv,因为它没有通过其verify_file()方法
自动拒绝解析/home/some.guy/tmp/ansible/test.inv,因为它没有通过其verify_file()方法
yaml拒绝解析/home/some.guy/tmp/ansible/test.inv,因为它没有通过其verify_file()方法
使用ini插件解析/home/some.guy/tmp/ansible/test.inv库存源
正在从/home/some.guy/.local/lib/python2.7/site-packages/ansible/plugins/callback/minimal.pyc加载stdout类型的最小回调插件v2.0
META:ran处理程序
正在尝试启动连接
使用连接插件网络\u cli
NXS-sw01 |失败!=>{
“msg:“回溯(最近一次调用):\n文件\“/usr/bin/ansible connection\”,第342行,在\n main()\n文件\“/usr/bin/ansible connection\”,第261行,在main任务中\n uuid=sys.argv[2]\n索引错误:列表索引超出范围\n”
EDIT2:我在Github上打开了一张关于这个问题的错误通知单:

在获得有关ansible network的帮助后,我能够解决这个问题。显然,我在我的主目录下安装了python2/3的其他副本,这是首选,如我的OP中的调试输出所示:

ansible python module location = /home/some.guy/.local/lib/python2.7/site-packages/ansible

从我的主目录中删除.local path后,我现在看到ansible--版本报告2.9.13,NXOS模块工作正常。

在模块文档中找不到
启用\u https
,该播放尝试有轻微的错误,已更正。我尝试了其他模块,如用于横幅的模块。问题似乎是如何连接正在分析信息。它试图引用“sys.argv[2]”的第二个元素但它不存在?参见第二个示例将false更改为true如果我变得更简单,并尝试设置state:缺席或state:present,我会得到完全相同的错误。解析连接信息以了解Ansible应如何尝试连接到交换机似乎真的是一个问题。甚至连runn的一部分都没有