这是我的问题我需要使用一个变量'target_host',然后将'_host'附加到它的值,以获得另一个我需要的变量名称.如果你看看我的剧本.任务nbr 1,2,3获取变量的值,但nbr 4无法完成我的预期.在ansible中有没有其他方法可以达到同样的目的?
---
- name: "Play to for dynamic groups"
hosts: local
vars:
- target_host: smtp
- smtp_host: smtp.max.com
tasks:
- name: testing
debug: msg={{ target_host }}
- name: testing
debug: msg={{ smtp_host }}
- name: testing
debug: msg={{ target_host }}_host
- name: testing
debug: msg={{ {{ target_host }}_host }}
Output:
TASK: [testing] ***************************************************************
ok: [127.0.0.1] => {
"msg": "smtp"
}
TASK: [testing] ***************************************************************
ok: [127.0.0.1] => {
"msg": "smtp.max.com"
}
TASK: [testing] ***************************************************************
ok: [127.0.0.1] => {
"msg": …Run Code Online (Sandbox Code Playgroud) ansible ×1