> > *general_var.yml*
> > main_dir: "{{ app_name }}-{{ ansible_hostname }}-{{ ver }}"
Use *vars* lookup plugin to indirectly reference the value of the
variable stored in *app_name*. Then use filter *product* to create
the combinations. For example, given
* the extra variable '-e app_name=dir_list'
* the variable *dir_list*
shell> cat dirname.yml
dir_list:
- hello
- goodbye
- take-care
* the inventory
shell> cat hosts
host01 ansible_hostname=
01.us.com
* the variable 'ver=123'
The variable *main_dir*
shell> cat general_var.yml
main_dir: "{{ lookup('vars', app_name)|
product([ansible_hostname])|
product([ver])|
map('flatten')|
map('join','-')|list }}"
gives the list you want (simplified)
main_dir:
- hello-01.us.com-123
- goodbye-01.us.com-123
- take-care-01.us.com-123
Test the iteration
- debug:
msg: "copy {{ item.0 }} to {{ item.1 }}"
with_nested:
- "{{ patch_lib }}"
- "{{ main_dir }}"
gives (abridged)
msg: copy lib_1 to hello-01.us.com-123
msg: copy lib_1 to goodbye-01.us.com-123
msg: copy lib_1 to take-care-01.us.com-123
msg: copy lib_2 to hello-01.us.com-123
msg: copy lib_2 to goodbye-01.us.com-123
msg: copy lib_2 to take-care-01.us.com-123
Fit the details to your needs.
--
Vladimir Botka