【问题标题】:Ansible overwrite hosts in role dependenciesAnsible 覆盖角色依赖中的主机
【发布时间】:2017-10-03 14:29:30
【问题描述】:

假设我有一个角色glusterfs,它在主机glusterfs-servers 上配置一个GlusterFS 集群。

此外,我有一个角色 storage-clients,它想从这个 GlusterFS 集群上挂载一个卷到主机 storage-clients

所以为了确保 GlusterFS 集群设置成功,我在role/storage-clients/meta/main.yml 中添加了以下内容:

---
dependencies:
  - { role: glusterfs, hosts: glusterfs-servers }

但这会导致 ansible 在 storage-clients 中的主机上运行 glusterfs 角色,这显然会失败。

在我的剧本中,我在storage-clients 角色之前有glusterfs 角色,但我想确保我的角色尽可能地防错。

这怎么可能?

【问题讨论】:

    标签: dependencies ansible


    【解决方案1】:

    角色的依赖被应用到与主角色相同的主机上。

    如果您需要设置一些安全网,请将一些检查任务添加到您的storage-clients 角色。例如:

    - name: Ensure glusterfs servers are ready
      script: check_glusterfs.sh
      delegate_to: '{{ item }}'
      with_items: '{{ groups["glusterfs-servers"] | default([]) }}'
      run_once: yes
    

    【讨论】:

      猜你喜欢
      • 2019-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-14
      • 2016-06-27
      • 2021-07-25
      • 1970-01-01
      • 2014-03-18
      相关资源
      最近更新 更多