ansible 2 \ include其他yml不起作用,虽然直接调用正在工作

时间:2016-06-26 06:08:46

标签: ansible ansible-playbook ansible-2.x

我的all.yml中有这个 无法运行tagger.yml(虽然直接运行tagger.yml时它正在运行)

---
  - name: run couple of ymls
    hosts: all
    tasks:
      - include: "./tagger.yml"
        #- include: ./fluentd.yml

tagger.yml

---
  - name: tagger - build docker
    hosts: all  
    tags:
      - all
      - tagger
....

错误是

fatal: [localhost]: FAILED! => {"failed": true, "reason": "no action detected in task. This often indicates a misspelled module name, or incorrect module path.\n\nThe error appears to have been in '.Build/tagger.yml': line 2, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n  - name: tagger - build docker\n    ^ here\n\n\nThe error appears to have been in '.Build/tagger.yml': line 2, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n  - name: tagger - build docker\n    ^ here\n"}

2 个答案:

答案 0 :(得分:1)

Ansible有两个“级别”,一个是剧本级别,您可以在其中提供游戏,另一个是任务级别,您可以在其中提供任务。包含适用于两个级别,但如果您已经处于任务级别,则无法包含新的游戏。

例如,这没关系:

main.yml

---
- include: play1.yml
- include: play2.yml

play1.yml

----
- name: run couple of tasks on all hosts
  hosts: all
  tasks: [{debug: {msg: "Task1"}}]

play2.yml

----
- name: run some more tasks on some hosts
  hosts: some
  tasks: [{debug: {msg: "Task2"}}]

正如main.yml中的那样,你仍然处于剧本级别,因此你可以包含文件,这些文件也是剧本本身。这意味着您也可以随时与play1.yml分开运行ansible-playbook

但是,一旦处于任务级别,您只能包含仅包含任务的文件:

main.yml

---
- name: run couple of ymls
  hosts: all
  tasks:
    - include: "task1.yml"
    - include: "task2.yml"

task1.yml

---
- name: An actual command
  debug: { msg: "Task 1" }

task2.yml

---
- name: An other actual command
  debug: { msg: "Task 2" }

这也没关系,因为task1.ymltask2.yml文件只包含任务,而且它们不是成熟的剧本。尝试使用ansible-playbook单独运行它们将不再有效,因为它们只是一堆任务。

请注意,在此示例中,如果您包含play1.yml而不是task1.yml,那么该剧本将失败,因为您已经处于“任务”级别,您可以在此处不再导入任何剧本。

答案 1 :(得分:0)

hosts文件中删除tagger.yml

---
  - name: tagger - build docker
    whatever task here 
    tags:
      - all
      - tagger

希望能帮到你