Ansible v2.2.1.0
如何修改Search Dictionary Values in Ansible中的答案才能执行此操作?
我有一本字典:
filenames_for_version:
1.0:
file1: "Hello.txt"
file2: "Goodbye.txt"
2.0:
file1: "HelloWorld.txt"
file2: "GoodbyeWorld.txt"
现在我想编写一个执行任务的任务......
- name: Get the corresponding **file1** for the version
set_fact: f1_4_ver={{ what do I put here??? }}
- name: Get the corresponding **file2** for the version
set_fact: f2_4_ver={{ what do I put here??? }}
我希望能够在调用我的剧本时将版本作为CLI参数传递,例如,
$ ansible-playbook -i "localhost," -c local get_filename_for_version.yml -e "version=1.0"
...如果我通过版本= 1.0,我得到......
f1_4_ver=Hello.txt
f2_4_ver=Goodbye.txt
...如果我通过版本= 2.0,我会......
f1_4_ver=HelloWorld.txt
f2_4_ver=GoodbyeWorld.txt
......中应包含哪些代码。
{{ what do I put here??? }}
......我的任务的一部分?
答案 0 :(得分:1)
您通过在变量/键名称中使用点来提出麻烦,但是:
{{ filenames_for_version[version].file1 }}
{{ filenames_for_version[version].file2 }}