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

Dynamically increase ansible_group_priority for selected env #909

Merged
merged 1 commit into from
Oct 30, 2017

Conversation

fullyint
Copy link
Contributor

This PR assigns higher priority to a user's indicated env group (if any).
Fixes https://discourse.roots.io/t/10756/2 originally reported at https://discourse.roots.io/t/6090

When the same hostname is used in both the [production] and [staging] groups, Ansible will always use the staging group vars, even if a user specifies -e env=production. This is because without a differing ansible_group_priority, Ansible loads sibling groups in alphabetical order and variables from the last group loaded win out.

Ansible 2.4 added the ansible_group_priority option to assign differing priority to sibling groups (feature in ansible/ansible#22580 and docs in ansible/ansible#28777).

I think the ansible_group_priority needs to be defined in the hosts/inventory file in order to affect which group_vars are given priority. However, the hosts file doesn't support jinja interpolation, so we can't use the regular hosts file(s) to dynamically set ansible_group_priority based on a user's indicated env. That is why this PR uses one of the Trellis plugins to set the priority via v2_playbook_on_play_start.

Users who wish to manually set ansible_group_priority for an env group in their hosts file(s) will need to use a value greater than the 20 used in this PR.

@swalkinshaw
Copy link
Member

Makes sense to default to this higher priority 👍

Otherwise when a host is in both the production and staging groups,
Ansible will always use the staging group vars, even if a user specifies
`-e env=production`. Without a differing ansible_group_priority,
Ansible loads sibling groups in alphabetical order and variables
from the last group loaded win out.
@fullyint fullyint force-pushed the ansible-group-priority branch from 85f4741 to 3add67b Compare October 30, 2017 00:17
@fullyint fullyint merged commit dd4f154 into master Oct 30, 2017
@fullyint fullyint deleted the ansible-group-priority branch October 30, 2017 01:23
primozcigler added a commit to primozcigler/trellis that referenced this pull request Nov 2, 2017
* trellis/master: (52 commits)
  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.
  Update placeholder deploy_build_before hook example [ci skip]
  Revert "Vagrant: Use DHCP by default"
  Vagrant: Use DHCP by default
  Extract package names from `apt` tasks into variables
  Remove `update_cache` parameter from `apt` tasks
  Normalize `apt` tasks and check package variables format
  Ansible 2.4 compatibility
  CHANGELOG updates
  Default h5bp expires and cache busting to false
  Remove WP transient _site_transient_theme_roots during deploys
  Deploys: Minimize delay in updating WP theme paths
  Fix multisite_subdomains Ruby compat
  Extract Trellis::Config (roots#890)
  Vagrant: Support DHCP
  Redirect directly to https canonical domain (roots#889)
  Ansible: Retry ssh connection one more time
  ...
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