From 88efda5725b3fce74a7527ac2631c9a9a0a6344f Mon Sep 17 00:00:00 2001 From: Christoph Sieber Date: Wed, 16 Oct 2024 17:26:26 +0200 Subject: [PATCH] add `renew_anon_volumes` parameter to `docker compose up` --- plugins/modules/docker_compose_v2.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/modules/docker_compose_v2.py b/plugins/modules/docker_compose_v2.py index 5ed873bb1..64f4a3b0b 100644 --- a/plugins/modules/docker_compose_v2.py +++ b/plugins/modules/docker_compose_v2.py @@ -93,6 +93,12 @@ - always - never - auto + renew_anon_volumes: + description: + - Whether to recreate instead of reuse anonymous volumes from previous containers + - V(true) is equivalent to the C(--renew-anon-volumes) or C(-V) option of C(docker compose up) + type: bool + default: false remove_images: description: - Use with O(state=absent) to remove all images or only local images. @@ -437,6 +443,7 @@ def __init__(self, client): self.remove_images = parameters['remove_images'] self.remove_volumes = parameters['remove_volumes'] self.remove_orphans = parameters['remove_orphans'] + self.renew_anon_volumes = parameters['renew_anon_volumes'] self.timeout = parameters['timeout'] self.services = parameters['services'] or [] self.scale = parameters['scale'] or {} @@ -477,6 +484,8 @@ def get_up_cmd(self, dry_run, no_start=False): args.append('--remove-orphans') if self.recreate == 'always': args.append('--force-recreate') + if self.renew_anon_volumes: + args.append('--renew-anon-volumes') if self.recreate == 'never': args.append('--no-recreate') if not self.dependencies: @@ -621,6 +630,7 @@ def main(): pull=dict(type='str', choices=['always', 'missing', 'never', 'policy'], default='policy'), build=dict(type='str', choices=['always', 'never', 'policy'], default='policy'), recreate=dict(type='str', default='auto', choices=['always', 'never', 'auto']), + renew_anon_volumes=dict(type='bool',default=False), remove_images=dict(type='str', choices=['all', 'local']), remove_volumes=dict(type='bool', default=False), remove_orphans=dict(type='bool', default=False),