Skip to content

Enable remove_orphans on all docker_compose_v2 deploys

jedmund requested to merge jedmund/remove-orphans-on-deploy into main

Created by: jedmund

Summary

Add remove_orphans: true to every Deploy task and Restart handler that calls community.docker.docker_compose_v2 across the role tree. Renaming a service or moving one between stacks (like the recent album-sort migration) no longer requires a manual docker rm of the old container — compose drops it on the next deploy of that stack.

Trade-off

If a service is accidentally removed from a compose file (typo, mid-merge state, transient branch checkout), it gets torn down on the next deploy rather than just generating an "orphan" warning. Considered acceptable here because:

  • Single operator
  • Stack files are version-controlled, so accidental removals are recoverable in seconds
  • Persistent data lives in named volumes, not container filesystems — remove_orphans only deletes containers

Scope

20 files touched: 10 tasks/main.yml Deploy tasks + 10 handlers/main.yml Restart tasks. The new musicbrainz role isn't on main yet and isn't included in this PR; it picks up the flag when that role lands.

Test plan

  • make deploy-content-management runs cleanly with no orphan warnings
  • Make a trivial rename in a stack (rename one service in compose), redeploy, confirm old container is removed automatically

Merge request reports

Loading