Deploy to multiple staging environments

I haven’t tried the ideas above, but the idea @cfx proposed sounds promising if you want your staging sites on different servers, as you seem to have indicated. If you add a new staging1 group to group_vars as suggested, I believe the implication would be that you also copy hosts/staging to hosts/staging1 and change the [staging] group name in the new file to [staging1].

New provision command: ansible-playbook server.yml -e env=staging1
New deploy command: ./bin/deploy.sh staging1 example.com (or whatever domain)


I suspect that a more common scenario would be that you want different sites to test different WordPress theme developments, not that you want different servers to test different server configs. In that case you could use a single staging server but deploy your different branches to different domains on the server. I have not tested the ideas below.

# group_vars/staging/wordpress_sites.yml

wordpress_sites:
  staging1.example.com
    site_hosts:
      - canonical: staging1.example.com
    repo: git@github.com:example/example.com.git
    branch: staging1
    ...
  staging2.example.com
    site_hosts:
      - canonical: staging2.example.com
    repo: git@github.com:example/example.com.git   # same repo as above
    branch: staging2
    ...

Then you could just list staging1.example.com and staging2.example.com in vault_wordpress_sites (in group_vars/staging/vault.yml) with all credentials repeated, or use a DRY modification like this:

# group_vars/staging/vault.yml
staging_example_com: 
  env:
    db_password: example_dbpassword
    # Generate your keys here: https://roots.io/salts.html
    auth_key: "generateme"
    secure_auth_key: "generateme"
    logged_in_key: "generateme"
    nonce_key: "generateme"
    auth_salt: "generateme"
    secure_auth_salt: "generateme"
    logged_in_salt: "generateme"
    nonce_salt: "generateme"

vault_wordpress_sites:
  staging1.example.com: "{{ staging_example_com }}"
  staging2.example.com: "{{ staging_example_com }}"

Your wordpress_sites indicates the correct branch so you won’t have to pass it as an option to your deploy command.
./bin/deploy.sh <environment> <site>
./bin/deploy.sh staging staging1.example.com
./bin/deploy.sh staging staging2.example.com

After deployment, you’d visit the sites/branches at their respective domains and find their files on the server at
srv/www/staging1.example.com
srv/www/staging2.example.com


For more alternatives and somewhat related Ansible options, see To deploy a second site

2 Likes