是否可以将其他标签应用于依赖角色?
Is it possible to apply an other tag to a dependency role?
我有一个这样的剧本,每个客户一个角色。
- 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 的 playbook 时,nginx 角色被执行。
有没有办法避免这种情况?
我知道可以 "export" 对 playbook 的依赖,它运行良好,但我认为这不是一个好的解决方案。
- 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
我有一个这样的剧本,每个客户一个角色。
- 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 的 playbook 时,nginx 角色被执行。 有没有办法避免这种情况?
我知道可以 "export" 对 playbook 的依赖,它运行良好,但我认为这不是一个好的解决方案。
- 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