Here is my problem I need to use one variable \'target_host\' and then append \'_host\' to it\'s value to get another variable name whose value I need. If you look at my pl
This is possible as of Ansible 2.5 with the vars lookup plugin, which I think is less likely to break without warning than some of the other methods posted here. For example:
---
- name: "Example of dynamic groups"
hosts: localhost
vars:
- target_host: smtp
- smtp_host: smtp.max.com
tasks:
- name: testing
debug: msg={{ lookup('vars', target_host + '_host') }}
Output:
PLAY [Example of dynamic groups] **************************************************
TASK [Gathering Facts] **************************************************
ok: [localhost]
TASK [testing] **************************************************
ok: [localhost] => {
"msg": "smtp.max.com"
}