在管理 Junos 设备时,排除 Ansible 收集和模块错误
问题
描述
在执行 Ansible 操作指南期间,控制节点会生成错误,指出 juniper.device 未找到集合、任务中未检测到任何操作或者无法解析模块。例如:
ERROR! couldn't resolve module/action 'juniper.device.facts'. This often indicates a misspelling, missing collection, or incorrect module path.
或
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
原因
Ansible 控制节点找不到 juniper.device 集合和关联的模块。
溶液
该系列 juniper.device 托管在 Ansible Galaxy 网站上。要使用集合中的模块,您必须将集合安装在 Ansible 控制节点上,并在您的操作指南中引用它。
要在 Ansible 控制节点上安装 juniper.device 集合,请执行命令 ansible-galaxy collection install 并指定 juniper.device。
user@ansible-cn:~$ ansible-galaxy collection install juniper.device
注意:
如果未在默认位置安装集合,则可能需要在 Ansible 设置中定义该集合的路径。有关安装集合和指定路径的详细信息,请参阅 Ansible 官方文档。
若要使用 juniper.device 集合模块,请在执行模块时引用完全限定的集合名称。例如:
---
- name: Get Device Facts
hosts: junos-all
connection: local
gather_facts: no
tasks:
- name: Get device facts
juniper.device.facts:
savedir: "{{ playbook_dir }}"