docker_compose - Fix startup errors for docker-compose versions <1.17.0 (#182)

* Initial Commit

* Adding changelog fragment

* Applying review suggestions
This commit is contained in:
Ajpantuso 2021-07-31 05:37:02 -04:00 committed by GitHub
parent 567561ada0
commit 03f649f43c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 9 deletions

View File

@ -0,0 +1,4 @@
---
bugfixes:
- docker_compose - fixes task failures when bringing up services while using ``docker-compose <1.17.0``
(https://github.com/ansible-collections/community.docker/issues/180).

View File

@ -146,6 +146,8 @@ options:
description: description:
- Use with I(state) C(present) to stop all containers defined in the Compose file. - Use with I(state) C(present) to stop all containers defined in the Compose file.
- If I(services) is defined, only the containers listed there will be stopped. - If I(services) is defined, only the containers listed there will be stopped.
- Requires C(docker-compose) version 1.17.0 or greater for full support. For older versions, the services will
first be started and then stopped when the service is supposed to be created as stopped.
type: bool type: bool
default: no default: no
restarted: restarted:
@ -807,15 +809,25 @@ class ContainerManager(DockerBaseClass):
with stderr_redirector(err_redir_name): with stderr_redirector(err_redir_name):
do_build = build_action_from_opts(up_options) do_build = build_action_from_opts(up_options)
self.log('Setting do_build to %s' % do_build) self.log('Setting do_build to %s' % do_build)
self.project.up( up_kwargs = {
service_names=service_names, 'service_names': service_names,
start_deps=start_deps, 'start_deps': start_deps,
strategy=converge, 'strategy': converge,
do_build=do_build, 'do_build': do_build,
detached=detached, 'detached': detached,
remove_orphans=self.remove_orphans, 'remove_orphans': self.remove_orphans,
timeout=self.timeout, 'timeout': self.timeout,
start=not self.stopped) }
if LooseVersion(compose_version) >= LooseVersion('1.17.0'):
up_kwargs['start'] = not self.stopped
elif self.stopped:
self.client.module.warn(
"The 'stopped' option requires docker-compose version >= 1.17.0. " +
"This task was run with docker-compose version %s." % compose_version
)
self.project.up(**up_kwargs)
except Exception as exc: except Exception as exc:
fail_reason = get_failure_info(exc, out_redir_name, err_redir_name, fail_reason = get_failure_info(exc, out_redir_name, err_redir_name,
msg_format="Error starting project %s") msg_format="Error starting project %s")