Successful provision, failing deployment; can't connect to database

This is probably my fault, since I manually updated Trellis at some point, and may have screwed something up. I’m just looking for guidance on where to look for the issue, what might be missing. I should add that I’m an Ansible newbie.

I’m deploying to a new AWS instance. The provisioning worked fine (returned with no errors), but deployment is failing with

Error: Error establishing a database connection
fatal: [my-site.com]: FAILED! => {"changed": false, "cmd": ["wp", "core", "is-installed"], "delta": "0:00:00.067139", "end": "2016-06-04 19:03:47.491505", "failed": true, "failed_when_result": true, "rc": 1, "start": "2016-06-04 19:03:47.424366", "stderr": "Error: Error establishing a database connection", "stdout": "", "stdout_lines": [], "warnings": []}

Mysql is running, and I can connect with root and the root password. I see that the database for my site has been made too. But I can’t connect to mysql with the configured db_user and password which has been saved to the .env file. If I run as root show grants; I don’t see any grants for the configured db_user at all.

I’m guessing some task didn’t run, possibly due to a missing file or missing reference, or a missing configuration variable somewhere.

Any ideas where I should start looking?

This thread should be a good starting point: Best practices to update Trellis

You can always just add the user/grants yourself. But if this task exists, then Ansible should be creating it.

Thanks to both of you – they were great starting points.

In my case I had in fact done something very similar for my upgrade to what was suggested in the thread you linked, cfx. But I guess I made a mistake…

That was a really useful link, swalkinshaw. I did have that task, and found from tracing the variables that I hadn’t spotted a merge conflict with the db_user and db_name variables. They were changed both in deploy.yml and in the group_vars/all/main.yml files. One had auto-merged, I think (and so was now a useful default string, but which was not the same as what I had been using before), while the other had possibly been a manual merge and I had kept my custom name and username.

So provisioning was setting up a certain database and user, and deployment was trying to use another.

Setting both to the same value fixed this for me. Thanks!

1 Like

@bjn can you remember how you traced these variables? I am seeing a similar issue but not sure how to debug it.

I think I probably just grepped the codebase for them. Sorry, but I don’t remember in any detail.