Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --yes parameter to docker compose up #1045

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions changelogs/fragments/1045-docker-compose-up-yes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- docker_compose_v2 - add ``assume_yes`` parameter for ``docker compose up`` (https://github.com/ansible-collections/community.docker/pull/1045).
17 changes: 17 additions & 0 deletions plugins/modules/docker_compose_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@
- When O(wait=true), wait at most this amount of seconds.
type: int
version_added: 3.8.0
assume_yes:
description:
- When O(assume_yes=true), pass C(--yes) to assume "yes" as answer to all prompts and run non-interactively.
- Right now a prompt is asked whenever a non-matching volume should be re-created. O(assume_yes=false)
results in the question not being answered, which will hang as it waits for stdin.
- This option is only available on Docker Compose 2.32.0 or newer.
type: bool
default: false
version_added: 4.5.0

author:
- Felix Fontein (@felixfontein)
Expand Down Expand Up @@ -444,6 +453,8 @@
is_failed,
)

from ansible_collections.community.docker.plugins.module_utils.version import LooseVersion


class ServicesManager(BaseComposeManager):
def __init__(self, client):
Expand All @@ -465,6 +476,9 @@ def __init__(self, client):
self.scale = parameters['scale'] or {}
self.wait = parameters['wait']
self.wait_timeout = parameters['wait_timeout']
self.yes = parameters['assume_yes']
if self.compose_version >= LooseVersion('2.32.0') and self.yes:
self.fail('assume_yes=true needs Docker Compose 2.32.0 or newer, not version %s' % (self.compose_version, ))

for key, value in self.scale.items():
if not isinstance(key, string_types):
Expand Down Expand Up @@ -522,6 +536,8 @@ def get_up_cmd(self, dry_run, no_start=False):
args.append('--no-start')
if dry_run:
args.append('--dry-run')
if self.yes:
args.append('--yes')
args.append('--')
for service in self.services:
args.append(service)
Expand Down Expand Up @@ -656,6 +672,7 @@ def main():
wait=dict(type='bool', default=False),
wait_timeout=dict(type='int'),
ignore_build_events=dict(type='bool', default=True),
assume_yes=dict(type='bool', default=False),
)
argspec_ex = common_compose_argspec_ex()
argument_spec.update(argspec_ex.pop('argspec'))
Expand Down
Loading