ansible 2 \包括其他yml不包括';虽然直拨电话起作用,但它不起作用
我有这个在我的所有 无法运行tagger.yml(尽管直接运行tagger.yml时它正在工作) tagger.ymlansible 2 \包括其他yml不包括';虽然直拨电话起作用,但它不起作用,ansible,ansible-playbook,ansible-2.x,Ansible,Ansible Playbook,Ansible 2.x,我有这个在我的所有 无法运行tagger.yml(尽管直接运行tagger.yml时它正在工作) tagger.yml --- - name: tagger - build docker hosts: all tags: - all - tagger .... 错误是 fatal: [localhost]: FAILED! => {"failed": true, "reason": "no action detected in task.
---
- 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"}
从
tagger.yml
文件中删除hosts
:
---
- name: tagger - build docker
whatever task here
tags:
- all
- tagger
希望帮助您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
中一样,您仍然处于playbook级别,因此您可以包含文件,这些文件本身也是playbook。这意味着您可以随时单独运行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.yml
和task2.yml
文件都只包含任务,它们不是完整的剧本。尝试使用ansible playbook
单独运行它们将不再有效,因为它们只是一堆任务
请注意,在本例中,如果包含
play1.yml
而不是像task1.yml
,则playbook将失败,因为您已经处于“任务”级别,您无法从中导入更多的剧本。谢谢:)不起作用…甚至从tagger.ymlnot标签中删除了标签,但主机将其删除,并显示结果/错误和配置正确-我还删除了主机。尝试了很多东西-我认为这与我不能在父母或孩子(或其他什么)的“任务”部分进行调查有关。感谢详细的答案-尝试了,现在它开始工作了!
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" }