【问题标题】:Ansible returning "no action detected in task"Ansible 返回“在任务中未检测到任何动作”
【发布时间】:2019-02-06 05:13:16
【问题描述】:

我在 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

当我运行 playbook 时,我收到一条错误消息告诉我:

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

我看到一个类似的问题,其中提问者拼错了模块的名称,但我很确定“时区”拼写正确,并且根据official docs,该模块在 2.7 中。我尝试从set-timezone.yaml 中删除hosts: all,却得到了这个错误:“包含的任务文件必须包含任务列表”。

【问题讨论】:

  • 你可以尝试通过从包含的播放中删除主机和任务行来运行任务,即从 set-timezone.yaml
  • 是的,成功了。谢谢!

标签: ansible ansible-2.x


【解决方案1】:

却得到了这个错误:“包含的任务文件必须包含任务列表”。

正确,“任务列表”部分的确切含义是:由本身是 ansible 任务的项目组成的 yaml 列表:

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

【讨论】:

  • 谢谢,解决了问题!我没有意识到您需要删除 hoststasks 行。
猜你喜欢
  • 2020-05-03
  • 1970-01-01
  • 2017-05-06
  • 2016-06-05
  • 2018-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多