Change variable in Ansible template based on group with children?

纵然是瞬间 提交于 2020-01-07 05:23:04

问题


I found Change variable in Ansible template based on group. However how do I extend the answer in groups with children?

If I extend the group vars file in the link above to

[host0]
host0.my-network.com
[host1]
host1.my-network.com

[es-masters:children]
host0
host1

How can I extend the above post's answer (shown below) to make it work with the group vars file above? Simply putting the FQDN in the jinja2 statement does not work.

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

回答1:


What you should do is:
Provide default in template

# role_name/templates/template.j2
node_master={{ role_name_node_master | default(true) }}

Than override in group_vars

# group_vars/es-masters.yml
role_name_node_master: false


来源:https://stackoverflow.com/questions/42955303/change-variable-in-ansible-template-based-on-group-with-children

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!