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

Disallow duplicate site keys within a host's wordpress_sites #910

Merged
merged 1 commit into from Nov 12, 2017

Conversation

fullyint
Copy link
Contributor

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/2

Why? 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 in group_vars/all/main.yml, including their custom env in the list.

Shouldn't choke on weird customizations. In case users have customizations such that the wordpress_sites.yml file is missing or the wordpress_sites dict is missing for an env, 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 single env group on a given playbook run. Thus we must manually load the vars files ourselves in order to access wordpress_sites from multiple environments simultaneously. Simultaneous access is necessary to check for duplicate site keys.

Example error message.

TASK [common : Fail if there are duplicate site keys within host's wordpress_sites] ****
---------------------------------------------------
If you put multiple environments on `138.68.203.29`, `wordpress_sites` must
use different site keys per environment. Adjust the following site keys that
are duplicated between the `production` and `staging` groups:
  - example.com
  - site2.io

failed: [138.68.203.29] (item=...)

Copy link
Member

@swalkinshaw swalkinshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jinja ninja

If a user loads both staging and production sites 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).
@fullyint fullyint merged commit 112a887 into master Nov 12, 2017
@fullyint fullyint deleted the validate-site-keys branch November 12, 2017 19:57
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.

None yet

2 participants