简体   繁体   English

我需要满足条件时使用ansible replace模块替换jinja2模板中变量的内容

[英]I need to replace the content of the variable in jinja2 template using ansible replace module when it satisfies when condition

I need to replace the content of the variable in jinja2 template using ansible replace module. 我需要使用ansible replace模块替换jinja2模板中变量的内容。

and in the same jinja2 template I need to replace some values when It satisfies the when condition. 在同一个jinja2模板中,当它满足when条件时,我需要替换一些值。 The when condition should be in jinja2 templates only. when条件应仅在jinja2模板中。

I have tried in couple of way as shown below but none of them were worked for me 我已经尝试了几种方法,如下所示,但是没有一个对我有用

do we have any way to use the when condition in the same jinja2 template. 我们有什么办法可以在同一jinja2模板中使用when条件?

- set_fact: result="{{ temp |  replace('nodeAgent', ''+value+'') | replace('nodeServrer', ''+result+'') when: (''+adu+'' == 'adt') }}"
- set_fact: result="{{ temp |  replace('nodeAgent', ''+value+'') | replace('nodeServrer', ''+result+'') |  when: (''+adu+'' == 'adt') }}"

Do something like: 做类似的事情:

{% if '+adu+' == 'adt' %}
nodeAgent
{% else %}
nodeServer
{% endif %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM