我有一些ubuntu和centos的剧本,我想用main.yml来检查“何时:ansible_os_family =='RedHat'或ansible_distribution =='Centos'”运行剧本(有些人很多:-))< / p>
如果我只是
-include: centos-xxx.yml
-include: centos-xaa.yml
-include: centos-xsss.yml
它将运行所有这些 我希望如果满足条件,剧本将会运行
我没有找到任何说明如何运行的文档包含:如果可能的话,我会尝试不为每个包含任务创建一个
感谢您的帮助
答案 0 :(得分:14)
您可以使用when conditional包含文件。事实上,这有点普遍。
- include: centos-xxx.yml
when: ansible_os_family == 'RedHat' or ansible_distribution == 'Centos'
- include: debian-xxx.yml
when: ansible_distribution == 'Debian'
根据您的评论 - 如果您想按顺序运行它们,您有两种选择。这是直截了当的:
- include: centos-a.yml
when: ansible_os_family == 'RedHat' or ansible_distribution == 'Centos'
- include: centos-b.yml
when: ansible_os_family == 'RedHat' or ansible_distribution == 'Centos'
- include: centos-c.yml
when: ansible_os_family == 'RedHat' or ansible_distribution == 'Centos'
- include: centos-d.yml
when: ansible_os_family == 'RedHat' or ansible_distribution == 'Centos'
或者,你可以这样做:
- include: centos.yml
when: ansible_os_family == 'RedHat' or ansible_distribution == 'Centos'
和centos.yml
内部:
- include: centos-a.yml
- include: centos-b.yml
- include: centos-c.yml
- include: centos-d.yml