Add 'detach' option to docker_stack module to control immediate exit behavior on stack deployment/remove (#987)

This commit is contained in:
aliou-sidibe 2024-11-17 15:30:32 +01:00 committed by GitHub
parent c17fef37b3
commit fb9784e4c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,2 @@
minor_changes:
- "docker_stack - allow to add ``--detach=false`` option to ``docker stack deploy`` command (https://github.com/ansible-collections/community.docker/pull/987)."

View File

@ -57,6 +57,14 @@ options:
current stack definition.
type: bool
default: false
detach:
description:
- If V(false), the C(--detach=false) option is added to the C(docker stack deploy) command,
allowing Docker to wait for tasks to converge before exiting.
- If V(true) (default), Docker exits immediately instead of waiting for tasks to converge.
type: bool
default: true
version_added: 4.1.0
with_registry_auth:
description:
- If true will add the C(--with-registry-auth) option to the C(docker stack deploy) command.
@ -200,6 +208,8 @@ def docker_stack_deploy(client, stack_name, compose_files):
command = ["stack", "deploy"]
if client.module.params["prune"]:
command += ["--prune"]
if not client.module.params["detach"]:
command += ["--detach=false"]
if client.module.params["with_registry_auth"]:
command += ["--with-registry-auth"]
if client.module.params["resolve_image"]:
@ -222,6 +232,8 @@ def docker_stack_inspect(client, stack_name):
def docker_stack_rm(client, stack_name, retries, interval):
command = ["stack", "rm", stack_name]
if not client.module.params["detach"]:
command += ["--detach=false"]
rc, out, err = client.call_cli(*command)
while to_native(err) != "Nothing found in stack: %s\n" % stack_name and retries > 0:
@ -237,6 +249,7 @@ def main():
'name': dict(type='str', required=True),
'compose': dict(type='list', elements='raw', default=[]),
'prune': dict(type='bool', default=False),
'detach': dict(type='bool', default=True),
'with_registry_auth': dict(type='bool', default=False),
'resolve_image': dict(type='str', choices=['always', 'changed', 'never']),
'state': dict(type='str', default='present', choices=['present', 'absent']),