我有这样的剧本,每个客户一个角色。
- hosts: hosting
roles:
- { role: client1, tags: ['client1'] }
- { role: client2, tags: ['client2'] }
例如,在每个角色上,我都依赖于nginx。
/roles/client1/meta/main.yml
dependencies:
- nginx
我不想在没有必要的时候启动nginx角色。所以我在依赖项中添加了 nginx 标签。
/roles/client1/meta/main.yml
dependencies:
- { role: nginx, tags: ['system'] }
但是当我使用标签 client1 启动剧本时,nginx 角色被执行。有没有解决方案可以避免这种情况?
我知道可以"导出"对剧本的依赖,效果很好,但我认为这不是一个不错的解决方案。
- hosts: hosting
roles:
- { role: nginx, tags: ['system'] }
- { role: client1, tags: ['client1'] }
- { role: client2, tags: ['client2'] }
标签不会相互覆盖,而是累积的。您的依赖项现在具有标记 client1
和 system
。
但这已经足够了。只需告诉 Ansible 在调用您的剧本时跳过系统标记:
ansible-playbook ... --tags client1 --skip-tags system