DB users not being created?

Majority of my projects are set up with bedrock, and now Im moving alle my projects from an MAMP flow to Vagrant/Trellis. I have set it up with my new main folder containing all my projects and the trellis folder. In wordpress_sites.yml under wordpress_sites i have added a section for each site. In vault.yml Ive set the vault_mysql_root_password and admin_password + db_password for all sites as well.
First time i ran vagrant up i had site_install: false and db_import: path for all sites since they we existing projects.
The provisioning went fine but an error occurred on db import, stating No access for the users.
Looking at mysql with vagrant ssh -> mysql -u root -p vault_mysql_root_password Ive checked, and no users are created.
What is the meaning of generating the env files with non existing db users? Am i missing something? Is it used for remote databases?

There should be db users created in that case I believe.

You can look here: https://github.com/roots/trellis/blob/master/roles/wordpress-setup/tasks/database.yml

DB users are skipped on when: not mysql_remote_database and item.value.db_create | default(True).

Based on what you said, that task should still run. You can debug that task though.

Hi @swalkinshaw - I really appreciate you taking your time replying us being stocked :sunny:
Ive tried destroying setting the box up again, no luck. Could you guide me on what kind of debugging?

It would be useful to see the output from Ansible. Was that task I linked skipped or did it run?

Also when using multiple sites, there may be a problem in using the same db user with each one. I’d also try changing the db_user for each site to be different. This is a good practice to separate them anyway.

@swalkinshaw Aha. I had db_create: false which of course was keeping the creation of db users task from running… I had set it to false because i was importing a db, so I thought that made sense? db_import: path

I guess it depends on your import script. Sometimes they create the database but they also might now. Or the script could just conditionally check if its exists.

I agree that…

So, in the case of importing a db using Trellis db_import, if db_create: false (the default is true), the users will not be set up, as you already noted in database.yml. Perhaps the user creation task could be moved after the db import task, and made to run if db_import is defined.

In the meantime, it looks like if you want to use db_import, you’ll need to leave db_create: true (the default) and site_install: false. When I tested a few weeks ago, it was ok to have the same db_user across sites, but you must have a different/unique db_name for each site/db.


Yes I agree that this make sense in case of setting up an existing bedrock project with Trellis. At least it was confusing me.

I can confirm this from my experience.

1 Like