Ansible 返回 "no action detected in task"

Ansible returning "no action detected in task"

我在 Debian Buster 上 运行ning 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

我看到一个类似的问题,其中提问者拼错了模块的名称,但我很确定 "timezone" 拼写正确并且该模块根据 official docs 在 2.7 中。我尝试从 set-timezone.yaml 中删除 hosts: all 并得到了这个错误:"included task files must contain a list of tasks".

and got this error instead: "included task files must contain a list of tasks".

正确,"list of tasks" 部分的意思就是:一个由本身是可执行任务的项目组成的 yaml 列表:

# cat set-timezone.yaml
---
- name: this is a task
  debug: msg="hello, world"
- name: set timezone to MST
  timezone:
    name: America/Denver