A few questions regarding staging and production

If both staging and production are on the same host/server, you’ll need to use one of the options described here: Production server provision configures Staging envs if hosts are the same - Bug or Intention?

Ansible tries to load all group_vars for the host it is targeting. If your host uses the same name/alias in multiple environments, Ansible loads group_vars for all applicable environments and the load order and resulting precedence for these values would be unpredictable, resulting in messed up variable values.

The PR roots/trellis#562 had a validate_one_env_group_only validation to detect and warn about this problem, but the PR never got traction and needs to be updated. I’ll PR Trellis with a validation for just this issue alone.


Q. Is it possible to have both staging and production trellis environments on the same box?
A. Yes it’s possible, but not recommended. Would require applying one of these options.

Q. During the deploy, does trellis reset the database password both for WordPress and MySql / MariaDB?
A. I’m not sure but I don’t think so. Once you’ve sorted out the host issue above, you should be able to get the answer via testing.

Q. how is vault_mysql_root_password from vault.yml treated if both environments are on the same machine?
A. If both environments are on the same machine, I think this particular password would need to be the same for both environments. But to answer your question, if you don’t apply the fixes mentioned above for multiple envs on same machine, Ansible will load vault_mysql_root_password from both environments in a nondeterministic sequence, so you can’t rely on which would take precedence.

Q. is env() trellis’ own function? I am used to getenv()
A. roots/bedrock#233: Use oscarotero/env instead of getenv

Q. Is it possible to check the actual values being used by application.php
A. SSH into server or VM, navigate to WP, use wp eval

$ cd /srv/www/example.com/current
$ wp eval 'echo DB_NAME . "\n";'
example_com_production

(but maybe that’s not exactly what you wanted)