You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ansible通过NETCONF推送配置至IOSXE交换机遇dict_keys迭代错误

问题:Ansible通过NETCONF向CML节点推送Playbook时触发iter() returned non-iterator of type 'dict_keys'错误

我正在学习Cisco DevNet的Ansible课程,向CML中的节点推送Playbook时,使用Cisco IOSXE模块的部分完全正常,但使用NETCONF时遇到如下错误,已排查约6小时仍未解决:

fatal: [10.0.15.5]: FAILED! => {"changed": false, "module_stderr": "iter() returned non-iterator of type 'dict_keys'", "module_stdout": "", "msg": "MODULE FAILURE
See stdout/stderr for the exact error"}

已尝试的排查操作

  • 在hosts文件及/group_var/cisco.yml文件中调整变量配置
  • 重启CML节点
  • 在Ubuntu、WSL及全新安装的RHEL环境中重试操作

当前文件结构及内容

目录结构

[admin@localhost Automation-Stuff\]$ ls
ansible.cfg   group_vars   hosts   host_vars   play.yml

ansible.cfg配置

[defaults]
gathering=explicit
inventory=./hosts
host_key_checking=False
deprecation_warnings=False
interpreter_python=/usr/local/bin/python3

hosts inventory文件

[cisco:vars]
ansible_connection=ansible.netcommon.netconf
netconf_port=830
ansible_user=admin
ansible_password=C1sco12345
ansible_become=yes
ansible_become_method=enable
ansible_network_os=cisco.ios.ios
subnet_id=5

Playbook文件play.yml

---
- name: NETCONF set NTP server
  hosts: cisco
  gather_facts: false

  tasks:

  - name: set ntp server
    ansible.netcommon.netconf_config:
      content: |
            <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
              <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
                <ntp>
                  <server xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ntp">
                    <server-list>
                      <ip-address>10.1.{{subnet_id}}.1</ip-address>
                    </server-list>
                  </server>
                </ntp>
              </native>
            </config>

执行Playbook的输出

[admin@localhost Automation-Stuff]$ ansible-playbook play.yml  
PLAY [NETCONF set NTP server] ************************************************************************************************************************************************************************************************************ 
TASK [set ntp server] ******************************************************************************************************************************************************************************************************************** 
fatal: [10.0.15.5]: FAILED! => {"changed": false, "module_stderr": "iter() returned non-iterator of type 'dict_keys'", "module_stdout": "", "msg": "MODULE FAILURE
See stdout/stderr for the exact error"} 
PLAY RECAP ******************************************************************************************************************************************************************************************************************************* 
10.0.15.5                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

内容的提问来源于stack exchange,提问作者Brandooooo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 18:14:53