Reloading updated group_vars/all mid-playbook execution

I’ve been struggling with this concept for a bit now and thought I had a solution but was unfortunately mistaken.

During a system upgrade scenario, in a lower version, we might have an ansible group_vars/all file file with 3 variables. In a higher version, we might add another variable to that file. Right now, I’ve done a merge, just copying the new variable over to the old file (for certain reasons, I couldn’t do a straight up file copy). After this, though, I need to reload the group_vars/all file to capture that 4th variable. I tried include_vars but the variable precedence is way too high to effectively use. That is, if we include a playbook as follows as follows, the variable will never be read as you’d expect/hope:

  • include: sub_playbook.yml new_var=value

If we run “include_vars” on group_vars/all where new_var is set as a default value of other_value, inside sub_playbook.yml, a debug of new_var will print “other_value” when we’d want “value.” However, it we do the merge in one playbook execution and then use the variable in the another one, the variable precedence is as we’d expect. This is all noted in the documentation but isn’t what we really need. Is there any way to “reload” the group_vars/all file without include_vars or at the very least, with a lower precedence where something like this will be feasible? I have also looked a the idea of just grepping for the new key-value pairs we’re adding to group_vars/all but then we run into the issue of reaching for variables defined across hosts and that might not be the best idea, though it is an option.

Thanks for any help!

have you tried?:

  • meta: refresh_inventory

It should refresh not only the inventory but reload all inventory files (host/group_vars included).

I did try that but it didn’t seem to work with the group_vars/all file. I haven’t tried to see what exactly it did refresh, but it wasn’t this.

Another note that I just got through trying set_fact with catting the group_vars/all file and reading the output lines. This didn’t work either as set_fact is just one lower precedence than include_vars. If there’s another module like set_fact, I can do this work around method as well but I haven’t seen/noticed anything.