Dynamically increase ansible_group_priority for selected env #909
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 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 differingansible_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 setansible_group_priority
based on a user's indicatedenv
. That is why this PR uses one of the Trellis plugins to set the priority viav2_playbook_on_play_start
.Users who wish to manually set
ansible_group_priority
for anenv
group in their hosts file(s) will need to use a value greater than the20
used in this PR.