Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix raw_vars functionality for Ansible 2.4.1 #915

Merged
merged 2 commits into from
Nov 6, 2017
Merged

Conversation

fullyint
Copy link
Contributor

@fullyint fullyint commented Nov 6, 2017

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 a task is passed to the VariableManager's get_vars(). Without a known basedir, no group_vars files are loaded, such that get_vars() no longer returns any group vars, only host vars and play vars. The basedirs 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 the v2_playbook_on_play_start callback, not during any particular task. Thus Trellis did not pass any task to get_vars(). With Ansible 2.4.1, this means the raw_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() to get_vars() just so basedirs will be populated and group vars retrieved. The is no other effect of passing in the task: task._role is None, task.environment is None, and task.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.

In Ansible 2.4.1 only, the VariableManager get_vars() does not return
group vars unless method parameters include a task object. Trellis
raw_vars functionality did not pass a task and thus did not receive
group vars and could not wrap the variable values in `{% raw %}`.
Temporarily feed a dummy Task() to get_vars() as a temporary fix
until the Trellis minimum Ansible requirement >= 2.4.2, when the
issue should be resolved in upstream Ansible.
@swalkinshaw
Copy link
Member

👍

@fullyint fullyint merged commit 9d67ada into master Nov 6, 2017
@fullyint fullyint deleted the fix-raw-vars branch November 6, 2017 20:08
primozcigler added a commit to primozcigler/trellis that referenced this pull request Nov 19, 2017
* tag '1.0.0-rc.2':
  1.0.0-rc.2
  Update to WP-CLI 1.4.1.
  Disallow duplicate site keys within a host's wordpress_sites (roots#910)
  Replace bare Dataloader() with pre-loaded play._loader (roots#917)
  Remove outdated to_unicode import from plugin utils (roots#916)
  Fix raw_vars functionality for Ansible 2.4.1 (roots#915)
  Enable ioapic
  Update vagrant_box_version to current release
primozcigler added a commit to proteusthemes/pt-ops that referenced this pull request Jan 5, 2018
* trellis/master: (292 commits)
  Bump Ansible version_tested_max to 2.4.2.0 (roots#932)
  Add MariaDB 10.2 PPA
  Remove cron_file if WP system cron disabled (roots#927)
  Add Code of Conduct [ci skip]
  Expose the deploy_helper keep_releases option (roots#922)
  Close roots#580 - Switch from .dev to .test
  Update acme-tiny commit hash
  Enable select deploy configs to optionally vary by site (roots#919)
  1.0.0-rc.2
  Update to WP-CLI 1.4.1.
  Disallow duplicate site keys within a host's wordpress_sites (roots#910)
  Replace bare Dataloader() with pre-loaded play._loader (roots#917)
  Remove outdated to_unicode import from plugin utils (roots#916)
  Fix raw_vars functionality for Ansible 2.4.1 (roots#915)
  Enable ioapic
  Update vagrant_box_version to current release
  Dynamically increase ansible_group_priority for selected env (roots#909)
  Bump Ansible version_tested_max to 2.4.1.0 (roots#911)
  Clarify DB task name.
  Update wp-cli to 1.4.0.
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants