【问题标题】:Is it possible to apply an other tag to a dependency role?是否可以将其他标签应用于依赖角色?
【发布时间】:2016-11-10 01:30:27
【问题描述】:

我有一本这样的剧本,每个客户一个角色。

- 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'] }

【问题讨论】:

    标签: ansible role


    【解决方案1】:

    标签不会相互覆盖,而是累积的。您的依赖项现在具有标签 client1system

    但这已经足够了。只需告诉 Ansible 在调用 playbook 时跳过系统标签即可:

    ansible-playbook ... --tags client1 --skip-tags system
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-11
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-18
      • 2022-01-18
      • 2015-09-19
      相关资源
      最近更新 更多