Skip to content

Fix local wp task paths in the database playbooks - #206

Merged
jasperf merged 4 commits into
mainfrom
fix/database-playbook-local-wp-paths
Aug 30, 2026
Merged

jasperf merged 4 commits into
mainfrom
fix/database-playbook-local-wp-paths

Conversation

@jasperf

@jasperf jasperf commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

wp-ops database-pull <site> production failed partway through with:

wp db export - | gzip > database_backup/<site>_development_<stamp>.sql.gz
/bin/sh: database_backup/<site>_development_<stamp>.sql.gz: No such file or directory

Every local (delegate_to: localhost) task in the database playbooks
chdir'd into {{ project_local_path }}/web/wp, but referenced its files
relative to {{ project_local_path }} — the directory one level up, where
database_backup/ is created and where the remote dump is fetched to.

The failure was not limited to the one task that reported it:

  • database-pull — the pre-import backup fails, and the import that follows
    would have failed the same way (gzip: <site>_db_dump.sql.gz: No such file or directory).
  • database-push — creates its dump in web/wp/, then copies from
    {{ project_local_path }}/{{ dump_file }}.
  • database-backup — same mismatch for a development environment export.

Changes

Local tasks now chdir to {{ project_local_path }}, matching the paths the
playbooks actually write, and pass --path=web/wp to wp so WordPress is
still found under Bedrock's layout regardless of whether the site ships a
wp-cli.yml.

Version bumped to 5.14.1 with a CHANGELOG entry.

Testing

  • ansible-playbook --syntax-check passes for all three playbooks against a
    real Trellis project.

The local tasks in database-pull, database-push and database-backup
chdir'd into {{ project_local_path }}/web/wp while referencing their
files relative to {{ project_local_path }} — the directory where
database_backup/ is created and where the remote dump is fetched to.

database-pull therefore died at "Export development database before
importing dump (backup)" with

    database_backup/<site>_development_<stamp>.sql.gz: No such file or
    directory

and the import that follows would have failed the same way on the dump
itself. database-push had the identical mismatch between the dump it
created and the copy that pushes it.

Chdir to {{ project_local_path }} instead, so the relative paths resolve
where the playbooks actually write, and pass --path=web/wp to wp so
WordPress is still found under Bedrock's layout.
The playbooks run their development-side steps with delegate_to: localhost
against local_path, which only works when WordPress and its database are
reachable from the host. With a Trellis VM dev site the host cannot see the
VM's database at all, so those steps can never succeed — but the README
presented the playbooks and the db-pull.sh/db-backup.sh scripts as
interchangeable alternatives, with nothing saying which setup each assumes.

Add a "Development Site Assumption" section to the overview, mapping each
playbook to its `trellis vm shell`-based equivalent, and cross-reference it
from Database Pull.
Pairing `chdir` with a bare relative path is what let the local tasks
write to a directory that was never created: the two only agree as long
as every task keeps them in sync by hand, and nothing enforces that.

Resolve the site's local_path against playbook_dir once, as
local_site_dir, and build every local file reference from it. Each path
now names its target outright, so a task's correctness no longer depends
on its working directory — or on ansible-playbook having been invoked
from the Trellis directory, which the previous relative paths silently
required. chdir stays only where `wp` runs, so a site's wp-cli.yml is
still picked up.

Deleting the local dump moves from `rm -f` to the file module, which
takes the absolute path directly and needs no shell at all.
@jasperf
jasperf merged commit 0cbe01e into main Aug 30, 2026
1 check passed
@jasperf
jasperf deleted the fix/database-playbook-local-wp-paths branch August 30, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant