diff --git a/changelogs/fragments/942-compose-v2-pull.yml b/changelogs/fragments/942-compose-v2-pull.yml new file mode 100644 index 000000000..415d15259 --- /dev/null +++ b/changelogs/fragments/942-compose-v2-pull.yml @@ -0,0 +1,3 @@ +minor_changes: + - "docker_compose_v2_pull - add new options ``ignore_buildable``, ``include_deps``, and ``services`` + (https://github.com/ansible-collections/community.docker/issues/941, https://github.com/ansible-collections/community.docker/pull/942)." diff --git a/plugins/modules/docker_compose_v2_pull.py b/plugins/modules/docker_compose_v2_pull.py index af9f3ae65..9141c1f32 100644 --- a/plugins/modules/docker_compose_v2_pull.py +++ b/plugins/modules/docker_compose_v2_pull.py @@ -47,6 +47,25 @@ - always - missing default: always + ignore_buildable: + description: + - If set to V(true), will not pull images that can be built. + type: bool + default: false + version_added: 3.12.0 + include_deps: + description: + - If set to V(true), also pull services that are declared as dependencies. + - This only makes sense if O(services) is used. + type: bool + default: false + version_added: 3.12.0 + services: + description: + - Specifies a subset of services to be targeted. + type: list + elements: str + version_added: 3.12.0 author: - Felix Fontein (@felixfontein) @@ -114,19 +133,32 @@ def __init__(self, client): parameters = self.client.module.params self.policy = parameters['policy'] + self.ignore_buildable = parameters['ignore_buildable'] + self.include_deps = parameters['include_deps'] + self.services = parameters['services'] or [] if self.policy != 'always' and self.compose_version < LooseVersion('2.22.0'): # https://github.com/docker/compose/pull/10981 - 2.22.0 self.fail('A pull policy other than always is only supported since Docker Compose 2.22.0. {0} has version {1}'.format( self.client.get_cli(), self.compose_version)) + if self.ignore_buildable and self.compose_version < LooseVersion('2.15.0'): + # https://github.com/docker/compose/pull/10134 - 2.15.0 + self.fail('--ignore-buildable is only supported since Docker Compose 2.15.0. {0} has version {1}'.format( + self.client.get_cli(), self.compose_version)) def get_pull_cmd(self, dry_run, no_start=False): args = self.get_base_args() + ['pull'] if self.policy != 'always': args.extend(['--policy', self.policy]) + if self.ignore_buildable: + args.append('--ignore-buildable') + if self.include_deps: + args.append('--include-deps') if dry_run: args.append('--dry-run') args.append('--') + for service in self.services: + args.append(service) return args def run(self): @@ -144,6 +176,9 @@ def run(self): def main(): argument_spec = dict( policy=dict(type='str', choices=['always', 'missing'], default='always'), + ignore_buildable=dict(type='bool', default=False), + include_deps=dict(type='bool', default=False), + services=dict(type='list', elements='str'), ) argspec_ex = common_compose_argspec_ex() argument_spec.update(argspec_ex.pop('argspec'))