Ansible运行提示找不到ansible.netcommon.netconf连接插件如何解决
问题排查及解决步骤
- 优先检查 inventory 中的变量配置(最高概率原因)
错误提示中出现的插件名携带ansible_connection:前缀,说明你在 inventory 定义ansible_connection变量时,错误将键名也写入了值中。
正确配置示例(INI 格式 inventory):
注意值只需要写[iosxr] ATL_isr_lab ansible_host=你的设备IP ansible_connection=ansible.netcommon.netconf ansible_network_os=cisco.iosxr.iosxr ansible_user=设备用户名 ansible_password=设备密码 LAX_isr_lab ansible_host=你的设备IP ansible_connection=ansible.netcommon.netconf ansible_network_os=cisco.iosxr.iosxr ansible_user=设备用户名 ansible_password=设备密码ansible.netcommon.netconf,不要带ansible_connection:前缀。 - 确认 collection 安装路径及版本
执行命令ansible-galaxy collection list ansible.netcommon,确认返回的安装路径在 ansible 识别的搜索路径范围内(你的环境搜索路径为/root/.ansible/collections:/usr/share/ansible/collections),如果不在可以在ansible.cfg的[defaults]段添加配置:
同时可以升级 netcommon 到适配 ansible core 2.11 的最新稳定版:collections_paths = 你的netcommon实际安装路径ansible-galaxy collection install ansible.netcommon --upgrade - 匹配连接类型与使用模块
你当前 playbook 中使用的ansible.netcommon.cli_command是 CLI 连接模式专属模块,如果要走 NETCONF 连接需要替换为 NETCONF 专属模块,例如ansible.netcommon.netconf_get;如果你确实需要执行 CLI 命令,将ansible_connection值修改为ansible.netcommon.network_cli即可。 - Playbook 显式指定必要参数
可以在 play 层级直接指定连接和操作系统参数,避免 inventory 配置不生效的问题:- hosts: iosxr connection: ansible.netcommon.netconf vars: ansible_network_os: cisco.iosxr.iosxr # 其余配置保持不变
内容的提问来源于stack exchange,提问作者Texia Plazaola
相关产品推荐
相关产品推荐

