如何在Ansible中将default与变量一起使用? [英] How can I use default with variable in Ansible?

查看:1115
本文介绍了如何在Ansible中将default与变量一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以在默认情况下使用简单的硬编码字符串,但我正在尝试这样做:

I know that I can use a simple hardcoded string in default but I am trying to do this:

myvar: "{{ lookup('env','var1') | default("{{var2}}",true) }}"

但是它将它添加为字符串而不是求值。

But it adds that as a string instead of evaluating it.

推荐答案

一旦打开Jinja2表达式使用 {{,您无需再次将其打开(特别是用引号引起来),就可以按其名称引用变量了:

Once you opened a Jinja2 expression with {{ you don't need to open it again (especially quoted) and you can refer to the variables by their names:

myvar: "{{ lookup('env','var1') | default(var2, true) }}"

这篇关于如何在Ansible中将default与变量一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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