Fix local wp task paths in the database playbooks - #206
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wp-ops database-pull <site> productionfailed partway through with:Every local (
delegate_to: localhost) task in the database playbookschdir'd into{{ project_local_path }}/web/wp, but referenced its filesrelative to
{{ project_local_path }}— the directory one level up, wheredatabase_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 followswould have failed the same way (
gzip: <site>_db_dump.sql.gz: No such file or directory).database-push— creates its dump inweb/wp/, then copies from{{ project_local_path }}/{{ dump_file }}.database-backup— same mismatch for a development environment export.Changes
Local tasks now
chdirto{{ project_local_path }}, matching the paths theplaybooks actually write, and pass
--path=web/wptowpso WordPress isstill 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-checkpasses for all three playbooks against areal Trellis project.