Fix raw_vars functionality for Ansible 2.4.1 #915
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes broken
raw_vars
functionality for Ansible 2.4.1.Background. In contrast to prior versions, Ansible 2.4.1 populates
basedirs
only if atask
is passed to theVariableManager
'sget_vars()
. Without a knownbasedir
, nogroup_vars
files are loaded, such thatget_vars()
no longer returns any group vars, only host vars and play vars. Thebasedirs
definitions and group vars retrieval should go back to normal in Ansible 2.4.2 (fix in ansible/ansible#32269).Implications for Trellis. The Trellis
raw_vars
feature retrieves and wraps var values in{% raw %}
using thev2_playbook_on_play_start
callback, not during any particular task. Thus Trellis did not pass anytask
toget_vars()
. With Ansible 2.4.1, this means theraw_vars
feature couldn't find nor process any group vars, risking jinja templating errors (e.g., for password vars with random characters).Implementation. This PR passes a dummy
Task()
toget_vars()
just sobasedirs
will be populated and group vars retrieved. The is no other effect of passing in thetask
:task._role
isNone
,task.environment
isNone
, andtask.get_vars()
returns{}
.Future. It should be ok to remove the dummy
task
once the Trellis minimum requirement for Ansible is 2.4.2+. I decided not to bother making the dummy task conditional on Ansible version 2.4.1 given that it had no problematic effects in 2.4.0 nor in 2.4.2.0-0.2.beta2.