Hello Vladimir,

It does works successfully. Many thanks and highly appreciated.

This thread is RESOLVED.

Thanks... WP

On Thursday, August 4, 2022 at 7:35:34 PM UTC-5 vbo...@gmail.com wrote:

> > On Wednesday, August 3, 2022 at 5:02:16 PM UTC-4 wpgpo...@gmail.com 
> wrote:
> > > *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
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/798676cd-5c65-4125-bfa8-9e47c6fca688n%40googlegroups.com.

Reply via email to