我正在尝试在Ansible中使用模块junos_get_facts
。我有一个主要的剧本和一些名为juniper.junos
的角色内的任务。我得到的问题是以下例外:
ansible-playbook main_pb.yml
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/Users/macuared/Ansible_projects/roles/juniper.junos/tasks/main.yaml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: Test junos_get_facts module
^ here
The error appears to have been in '/Users/macuared/Ansible_projects/roles/juniper.junos/tasks/main.yaml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: Test junos_get_facts module
^ here
exception type: <class 'ansible.errors.AnsibleParserError'>
exception: no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/Users/macuared/Ansible_projects/roles/juniper.junos/tasks/main.yaml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: Test junos_get_facts module
^ here
〜/ Ansible_projects / main_pb.yml
---
- name: Gathering Info from devices
hosts: man3-rc-test4200-01
connection: local
gather_facts: no
roles:
- { role: 'juniper.junos', when: DEVICE_TYPE == 'info' }
〜/ Ansible_projects /角色/ Juniper.junos /任务/ main.yaml
---
- name: Test junos_get_facts module
tasks:
- name: "TEST 1 - Gather Facts"
junos_get_facts:
host: "{{ inventory_hostname}}"
user: "YYYYYYY"
passwd: "XXXXXXX"
ignore_errors: True
register: junos
# - debug: var=junos
- name: Check TEST 1
assert:
that:
- junos.facts.hostname
- junos.facts.serialnumber
- junos.facts.model
- junos.facts.fqdn
我不太清楚这里的问题是什么。我正在使用virtualenv,我已经安装了所有的依赖项。
答案 0 :(得分:1)
角色中的任务文件应包含任务列表。
另一方面,您的文件包含单个元素列表,其中包含包含name
和tasks
个键的字典。 Ansible因此没有找到任何定义的动作(name
声明是正确的,但tasks
不是动作模块。)
所以你的main.yaml
应该是这样的:
---
- name: "TEST 1 - Gather Facts"
junos_get_facts:
host: "{{ inventory_hostname}}"
user: "YYYYYYY"
passwd: "XXXXXXX"
ignore_errors: True
register: junos
- name: Check TEST 1
assert:
that:
- junos.facts.hostname
- junos.facts.serialnumber
- junos.facts.model
- junos.facts.fqdn
在playbook中,任务是在tasks
下定义的,但在角色中,目录结构已经确定了。
答案 1 :(得分:0)
开箱即用Ansible有junos_facts,但junos_get_facts是需要单独安装的自定义模块。