Hi, I have a main.yml which include 1.yml and 2.yml.
1.yml has one task to append a new variable in local vars file - “vars.yml”.
2.yml uses vars file - “vars.yml” and must use the new variable which is appended by 1.yml.
I did some test. 2.yml cannot find out the new variable and it always load the original vars file.
Do you have any solution to resolve my question? Thank you!
I am not sure if dynamically updating vars file, would take effect in the same playbook, probably you can use ‘register’ to add this dynamic variable, and later down access it using hostvars.
Playbooks should not be dynamically editing yaml variable files.
Do use register, we have also theorized including a “set_variable” action plugin for adding new variables if need be, but in most cases register is all you need.