ansible 实际上使用“include”作为关键字吗?

ansible 实际上使用“include”作为关键字吗?

我继承了一个类似剧本的文件,thing.yaml其中包含以下内容:

---
- include: one.yaml
- include: two.yaml

ansible-playbook我通常使用one.yamland启动 yaml 文件two.yaml,但thing.yaml被拒绝:

ERROR! 'include' is not a valid attribute for a Play

The error appears to be in '.../thing.yaml': line 2, column 3, but
may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- include: one.yaml
  ^ here

哪个命令行会吃掉包含这样的文件?

答案1

include模块在 2.16 版本中已被弃用ansible,因为

根据关键字组合,它有太多冲突的行为,并且不清楚它在每种情况下应该如何表现。针对每个案件和相关行为制定了具体的新行动。

来源:Ansible 文档

替代方案是include_tasks,import_tasksimport_playbook。 (我个人猜测是include_role也有,但没有列出。)

答案2

你要找的是include_tasks,不是include。看https://docs.ansible.com/ansible/2.8/modules/include_tasks_module.html

相关内容