簡體   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

我需要使用ansible replace模塊替換jinja2模板中變量的內容。

在同一個jinja2模板中,當它滿足when條件時,我需要替換一些值。 when條件應僅在jinja2模板中。

我已經嘗試了幾種方法,如下所示,但是沒有一個對我有用

我們有什么辦法可以在同一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') }}"

做類似的事情:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM