Skip to content

Add trellis vault generate command - #749

Open
swalkinshaw wants to merge 1 commit into
yamleditfrom
vault-generate
Open

swalkinshaw wants to merge 1 commit into
yamleditfrom
vault-generate

Conversation

@swalkinshaw

Copy link
Copy Markdown
Member

Stacked on #748. Merge that first; this PR's base will then switch to master.

Fixes #426

Adds trellis vault generate to fill in passwords and WordPress keys/salts in group_vars/<env>/vault.yml. It's for projects that weren't created with trellis new, such as ones cloned from a template repo.

trellis vault generate [--force] [--salts-only] [ENVIRONMENT]
  • Generates only values that are missing, empty, or placeholders: generateme and the example values in Trellis's default vaults (devpw, example_dbpassword, ...). Running it again reports "No secrets to generate".
  • Never replaces Jinja templated values ({{ ... }}), even with --force
  • Uses the site names from each environment's wordpress_sites.yml, so multisite projects work
  • Comments and all other values are preserved through yamledit
  • Encrypted vaults are decrypted with ansible-vault decrypt --output - and re-encrypted by piping to ansible-vault encrypt --output <file>, so the plaintext is never written to disk
  • --force regenerates values that are already set and requires an ENVIRONMENT argument, so production database or user passwords can't be rotated by accident. --force --salts-only production is a safe way to rotate salts.

trellis new

new now uses the same code with force enabled to update the downloaded vault.yml files in place instead of overwriting them, so Trellis's comments stay. GenerateVaultConfig, the Vault structs, and WriteYamlFile are removed because nothing uses them any more.

Behaviour change: admin_password is now generated only for development. It's only used by the wordpress-install role, which runs only in development, and upstream's staging and production vaults don't include it.

Testing

  • Unit tests for placeholder filling, --force, --salts-only, templated values, multiple sites, idempotency, and new's vault update
  • Command tests, including encrypted vaults (with mocked ansible-vault) and a decryption failure
  • Tested by hand against a real ansible-vault-encrypted production vault: 11 placeholders filled, an existing real db_password kept, comments preserved, the file still encrypted afterwards, and a second run generated nothing

🤖 Generated with Claude Code

Generates passwords and WordPress keys/salts in group_vars/<env>/vault.yml
for projects that weren't created with `trellis new` (e.g. cloned from a
template repo). Fixes #426.

Only missing, empty, or placeholder values ("generateme" and the example
passwords in Trellis' default vaults) are generated, so it's idempotent.
Comments and other values are preserved via yamledit, and Jinja templated
values are never replaced. Encrypted vaults are decrypted and re-encrypted
by piping through ansible-vault so plaintext never touches disk.

  --force       regenerate all secrets (requires ENVIRONMENT)
  --salts-only  only the WordPress keys and salts

`trellis new` now uses the same code (with force) to update the
downloaded vault.yml files in place instead of overwriting them, keeping
Trellis' comments. It also no longer adds `admin_password` to non-development
vaults since it's only used by the wordpress-install role in development.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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