I am trying to shrink several chunks of similar code which looks like:
- ... multiple things is going here
register: list_register
- name: Generating list
set_fact: my_list="{{ list_register.results | map(attribute='ansible_facts.list_item') | list }}"
# the same code repeats...
In fact, the only difference between them is that I am using different list names here instead of my_list
In fact I want to do this:
set_fact:
"{{ some var }}" : "{{ some value }}"
I came across this post but didn't find any answer here.
Is it possible to do so or is there any workaround?
It creates a string of inline module parameter expression by concatenating value of
some_var
(fact name), separator=
and value ofsome_value
(fact value).As of 2018, using ansible v2.7.1, the syntax you suggest in your post works perfectly well.
At least in my case, I have this in role "a" :
And that in role "b" :
And execution goes :
take a look at this sample playbook:
The above does not work for me. What finally works is
Which is in the end obvious. You construct a string (the outer double quotes) which is then interpreted as a hash. In hashes key and value must be single quotes (the inner single quotes around the variable replacements). And finally you just place your variable replacements as in any other string.
Stefan