![](/img/trans.png)
[英]How can I find the user ID using ansible and use that in a jinja2 template?
[英]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.