【发布时间】:2022-01-12 21:23:04
【问题描述】:
需要一些帮助才能从 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 }}"
这段代码完美运行
任务 [打印] ******************************************* ****************************************************** ****************************************************** ************************************ 好的:[本地主机] => { “味精”:[ "10.88.55.00", “根”, “嘘!” ] }
但根据我的要求,我必须根据我的剧本中的位置检索 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 }}"}
【问题讨论】: