The Goal:
To have an array constant on Bedrock:
define('ARRAY_OF_SECRETS', [
'password_1',
'password_2',
...
'password_x',
]);
Questions:
Is it possible to:
save these passwords in Trellis’ ansible vault
“render” the passwords as environment variables
“build” the PHP constant
I’ve tried adding variables in env
inside wordpress_sites
. However, it seems array
is not supported.
General comment for Trellis
If it turns out that the group_vars/all defaults actually only apply to dev (I haven’t checked), they could be moved somewhere into group_vars/dev, to avoid the confusion that they don’t apply to remotes.
Global env for @bjn
I haven’t tested, but I’m guessing you could create your custom env as a dictionary in group_vars/all/main.yml:
custom_env:
env_var_1: value_1
env_var_2: value_2
Then, in your wordpress_sites for production and staging…
wordpress_sites:…
Thanks!
It’s not possible unfortunately. We use .env
which are supposed to be just environment variables which basically only supports strings (in reality it’s a bit more).
For anyone who facing the same issue:
$prefix = 'password_';
$index = 1;
while (! empty(Env::get($prefix . $index))) {
$secrets[] = (string) Env::get($prefix . $index);
$index++;
}
define('ARRAY_OF_SECRETS', $value);
Real life example: https://github.com/TypistTech/wp-password-argon-two-env/blob/0be822dfe9b615b7d9b10b43ac03376a90ef08f2/src/Converter.php#L47-L61
1 Like