Change variable in Ansible template based on group

前端 未结 4 1331
自闭症患者
自闭症患者 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 20:05

    If your inventory does not identify hosts with ansible_fqdn, ansible_hostname, etc., you can also use group_names to check if the current host has "es-masters" as one of its groups.

    {% if 'es-masters' in group_names %}
    node_master=true
    {% else %}
    node_master=false
    {% endif %}
    

    See https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#accessing-information-about-other-hosts-with-magic-variables

提交回复
热议问题