问题原文
原帖链接 · Nilesh · CC BY-SA 3.0
I have 3 ansible playbook.
my_ansible
├── hosts
├── play1.yaml
├── play2.yaml
├── play3.yaml
└── roles
├── role1
├── role2
└── role3
hosts
[play1]
host1
[play2]
host2
[play3]
host3
Now, when I run play3, I want to run play2(role2) on host2 and play1(role1) on host1.
I check, role-dependency, but that apply on same host, means, if I add role-dependency in role3 for role1 and role2, then these 2 roles will run against host3.
I want to make sure, play1 runs on host1 only, play2 runs on host2 only and play3 runs on host3 only.
I try to find the playbook dependency, but no luck yet.
If is there any better way to solve this, then I am ready to head into that way too.
已采纳解答
原帖链接 · Henrik Pingel · CC BY-SA 3.0
I guess the easiest way to achieve this is to create a master playbook and define the order of playbooks there.
It is possible to include playbooks inside a master playbook. [...] The plays and tasks in each playbook listed will be run in the order they are listed, just as if they had been defined here directly.
See Ansible documentation on playbooks reuse includes
In order to achieve that play3 runs play2 and play1 as well one would just need to define a master playbook like this:
---
- import_playbook: play3.yml
- import_playbook: play2.yml
- import_playbook: play1.yml
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
