Change variable in Ansible template based on group

前端 未结 4 1327
自闭症患者
自闭症患者 2021-02-05 19:25

I\'ve got an Ansible inventory file a bit like this:

[es-masters]
host1.my-network.com

[es-slaves]
host2.my-network.com
host3.my-network.com

[es:children]
es-m         


        
4条回答
  •  有刺的猬
    2021-02-05 19:58

    To avoid error with non existing group you should check first if the group exists:

    {% if 'es-masters' in group_names and ansible_fqdn in groups['es-masters'] %}
    node_master=true
    {% else %}
    node_master=false
    {% endif %}
    

提交回复
热议问题