我在 Debian Buster 上运行ansible-playbook
版本 2.7.6+dfsg-1。我有一本剧本,其中包括另一本剧本,如下所示:
---
- hosts: "{{ target }}"
tasks:
- include_tasks: set-timezone.yaml
包含set-timezone.yaml
的内容如下:
---
- hosts: all
tasks:
- name: set timezone to MST
timezone:
name: America/Denver
当我运行剧本时,我收到一个错误,告诉我:
no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/etc/ansible/playbooks/set-timezone.yaml': line 2, column 3, but maybe elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- hosts: all
^ here
我看到一个类似的问题,其中提问者拼错了模块的名称,但我很确定"时区"拼写正确,并且根据官方文档,该模块在 2.7 中。我尝试从set-timezone.yaml
中删除hosts: all
,但收到此错误:"包含的任务文件必须包含任务列表"。
并得到此错误:"包含的任务文件必须包含任务列表"。
正确,"任务列表"部分的意思正是:由本身就是 ansible 任务的项目组成的 yaml 列表:
# cat set-timezone.yaml
---
- name: this is a task
debug: msg="hello, world"
- name: set timezone to MST
timezone:
name: America/Denver