从ansible剧本中的var文件中检索变量值



需要一些帮助才能从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"]}

但根据我的要求,我必须根据我的剧本中的位置检索一个fs_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 }}"}

你能试试这种方法吗

- name: Print
debug:
msg:
- "{{ vars[location]['onefs_host'] }}"
- "{{ api_user }}"
- "{{ api_password }}"

最新更新