Skip to content

Commit

Permalink
Add 'detach' option to docker_stack module to control immediate exit …
Browse files Browse the repository at this point in the history
…behavior on stack deployment/remove (#987)
  • Loading branch information
aliou-sidibe authored Nov 17, 2024
1 parent c17fef3 commit fb9784e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/987-docker-stack-detach.yml
Original file line number Diff line number Diff line change
@@ -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)."
13 changes: 13 additions & 0 deletions plugins/modules/docker_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
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.
Expand Down Expand Up @@ -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"]:
Expand All @@ -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:
Expand All @@ -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']),
Expand Down

0 comments on commit fb9784e

Please sign in to comment.