Hello,
I send this message to ansible-devel as I think it is an advanced subject that can lead to a devel discussion.
The following play currently works as expected (or at least as I expected :
- hosts: localhost
gather_facts: no
vars:
var1: var2
tasks:
- name:
set_fact: “{{ var1 }}=test” - name: debug
debug: var=var2
It outputs “test”, meaning that the var1 variable has been expanded to var2 in the variable space.
Even though if this kind of feature can be very dangerous in the wrong hands, this can be helpful (and can help me solve an issue I have) to generate facts whose names depend on configurations that have been made in group_vars
In my case, I have several groups that define several lists of repositories to clone at specific revisions : HEAD, HEAD~1, …
I need to find a way, for each of these clones, to grab its git sha, and make it available to the rest of the playbook.
example of list (appid are uniques across all vars)
apps:
-
appid: app1
repo: repo_url
branch: HEAD -
appid: app2
repo: repo_url
branch: HEAD~1
with the feature mentioned above, I could easily generate new facts:
app1_sha: ab324ccd…
app2_sha: a23324ce…
now my question is :
can I rely on the implementation and consider that this “variable variables” feature of set_fact is indeed a feature and will not disappear in future releases ?
Thank you
Jerome