Hello,

I am not sure it helps in your case, but I had success in past generating
complex structures with a json template and importing it into a variable:

set_fact:
data: "{{ lookup('template', 'templates/data.json.j2') }}"

It's much faster than doing combines and loops.

Nuno Jordão

On Mon, Feb 15, 2021 at 11:32 AM Rishare Rishare <[email protected]> wrote:

>
> Hi,
>
> I can't find any easy way how to do something like this:
> - set_fact:
>     "mydict[{{ myvar }}]": "value"
>    vars:
>      myvar: "blabla"
>
> However it does not work, because the variable name is not evaluated. The
> only way I found to do this is very ugly:
> - set_fact:
>     mydict: "{{ mydict | combine({ myvar: 'value' }, recursive=true) }}"
>   vars:
>     myvar: "blabla"
>
> That is very ugly and can get out of hand quickly when going into deeper
> nested dictionaries.
>
> Any ideas how to make it "nicer"?
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/a7a6a255-65b1-48ef-9f21-1f71023b3933n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/a7a6a255-65b1-48ef-9f21-1f71023b3933n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAEAA%3DttrGM%2BC2wOD83yANRDhq6Z8M1bvqye1B3t1xFvHTdHFpQ%40mail.gmail.com.

Reply via email to