Disallow duplicate site keys within a host's wordpress_sites #910
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.
What? This PR adds a validation to prevent duplicate site keys when a host is in multiple
env
groups simultaneously. Fixes https://discourse.roots.io/t/10756/2Why? If a user loads a site's staging and production environment on a single host, site keys must differ between environments to prevent conflict that would otherwise occur in resources built from site keys (e.g., Nginx conf filepaths). Loading both production and staging on a single server is discouraged, but at least this PR prevents one of the most certain accompanying problems.
Rarely runs. This validation skips in the usual case that a host is only in a single
env
group.To disable. Hate it? Have a special case when you don't want the validation? Define
validate_site_keys: false
.Custom envs? If people have custom environments and care to have them validated by this PR's procedure, they can redefine
env_groups
ingroup_vars/all/main.yml
, including their customenv
in the list.Shouldn't choke on weird customizations. In case users have customizations such that the
wordpress_sites.yml
file is missing or thewordpress_sites
dict is missing for anenv
, the validation in this PR won't choke with a yaml or jinja failure, but no validation will occur.Loads files manually. Ansible only loads
wordpress_sites
vars from a singleenv
group on a given playbook run. Thus we must manually load the vars files ourselves in order to accesswordpress_sites
from multiple environments simultaneously. Simultaneous access is necessary to check for duplicate site keys.Example error message.