[英]Ansible vars not substituting variables inside dictionary
我有以下變量和字典:
My_VAR1: "Hello"
My_VAR2: "My_DIC1"
My_DIC1:
key1: "{{ My_VAR1 }} World"
My_VAR3: "{{ vars[My_VAR2]['key1'] }}"
但它似乎 vars 不能替代變量,我得到以下 output:
TASK [output : {{ My_VAR1 }} World] ***
有沒有辦法強制 vars 替換變量並獲得以下 output:
TASK [output : Hello World] ***
問: “有沒有辦法強制 vars 替換變量並獲得以下輸出”
TASK [output : Hello World]
- 答:下面的戲
vars:
My_VAR1: Hello
My_VAR2: "{{ My_VAR1 }} World"
My_VAR3: "{{ My_VAR2 }}"
tasks:
- debug:
var: My_VAR3
給
"My_VAR3": "Hello World"
問: “My_VAR2 是字典……”
A: 使用帶有vars插件的查找。 下面的劇本給出了同樣的結果。
vars:
My_VAR1: Hello
My_DIC1:
key1: "{{ My_VAR1 }} World"
My_VAR2: "My_DIC1"
My_VAR3: "{{ lookup('vars', My_VAR2).key1 }}"
tasks:
- debug:
var: My_VAR3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.