需要一些幫助才能從 var 檔案中檢索子值。
下面是我的var檔案
api_user: root
api_password: !vault |
$ANSIBLE_VAULT;1.2;AES256;isi33835326238346338613761366531376662613865376263656262
6138
Huston:
onefs_host: 10.88.55.00
Phoenix:
onefs_host: 10.76.52.01
下面是我的劇本
---
- name: isi_increase
hosts: localhost
connection: local
vars_files:
- isilonvars.yml
tasks:
- name: Print
debug:
msg:
- "{{ Huston.onefs_host }}"
- "{{ api_user }}"
- "{{ api_password }}"
這段代碼完美運行
任務 [列印] ************************************************ ****************************************************** ****************************************************** ****************************** ok: [localhost] => { "msg": [ "10.88.55.00", "根”,“Sh00tm3!” ] }
但是根據我的要求,我必須根據劇本中的位置檢索 onefs_host IP。我在這里使用額外的變數 -e "location=Huston"
- name: Print
debug:
msg:
# - "{{ wcc.onefs_host }}"
- "{{ {{location}}.onefs_host }}"
- "{{ api_user }}"
- "{{ api_password }}"
我收到以下錯誤。
fatal: [localhost]: FAILED! => {"msg": "template error while templating string: expected token ':', got '}'. String: {{ {{isilon_location}}.onefs_host }}"}
uj5u.com熱心網友回復:
你可以試試這個方法嗎
- name: Print
debug:
msg:
- "{{ vars[location]['onefs_host'] }}"
- "{{ api_user }}"
- "{{ api_password }}"
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/377459.html
上一篇:基于文本的游戲的函式呼叫
