根据带孩子的小组更改Ansible模板中的变量? [英] Change variable in Ansible template based on group with children?

查看:55
本文介绍了根据带孩子的小组更改Ansible模板中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在基于组的Ansible模板中更改变量.但是,如何在有孩子的小组中扩展答案?

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

如果我将上面链接中的group vars文件扩展到

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

如何扩展以上帖子的答案(如下所示)以使其与上方的group vars文件一起使用?只是将FQDN放在jinja2语句中是行不通的.

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 %}

推荐答案

您应该做的是:
在模板中提供默认值

What you should do is:
Provide default in template

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

比在group_vars中覆盖

Than override in group_vars

# group_vars/es-masters.yml
role_name_node_master: false

这篇关于根据带孩子的小组更改Ansible模板中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆