Question:
I have this in vars:
1 2 3 4 |
var1: "test1" var2: "test2" var3: "{{var1}}" |
Now I want to dynamically change var3: "{{var2}}"
.
I can assign var3: "test2"
. But how can I assign var3: "{{var2}}"
?
Answer:
My attempt at the interpretation of the phrase “dynamically change Ansible variable” based on your question:
1 2 3 4 5 6 7 8 9 10 11 12 |
--- - hosts: localhost connection: local vars: var1: "test1" var2: "test2" var3: "{{var1}}" tasks: - debug: var=var3 - set_fact: var3: "{{var2}}" - debug: var=var3 |
Variables assigned through a set_fact
module are in their own class of variables which has a lower priority only to block vars, task vars and extra vars. See Variable Precedence.