mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-09-12 19:07:24 +00:00
(cherry picked from commit bc8f6a6906)
This commit is contained in:
@@ -124,12 +124,15 @@ class AnsibleDockerClientBase(object):
|
||||
# Python 2.7 does not like anything than '**kwargs' after '*args', so we have to do this manually...
|
||||
pass
|
||||
|
||||
# def call_cli_json(self, *args, check_rc=False, data=None, cwd=None, environ_update=None, warn_on_stderr=False):
|
||||
# def call_cli_json(self, *args, check_rc=False, data=None, cwd=None, environ_update=None, warn_on_stderr=False, parse_empty_as_none=False):
|
||||
def call_cli_json(self, *args, **kwargs):
|
||||
warn_on_stderr = kwargs.pop('warn_on_stderr', False)
|
||||
parse_empty_as_none = kwargs.pop('parse_empty_as_none', False)
|
||||
rc, stdout, stderr = self.call_cli(*args, **kwargs)
|
||||
if warn_on_stderr and stderr:
|
||||
self.warn(to_native(stderr))
|
||||
if parse_empty_as_none and not stdout.strip():
|
||||
return rc, None, stderr
|
||||
try:
|
||||
data = json.loads(stdout)
|
||||
except Exception as exc:
|
||||
|
||||
@@ -647,7 +647,7 @@ def update_failed(result, events, args, stdout, stderr, rc, cli):
|
||||
result['failed'] = True
|
||||
result['msg'] = '\n'.join(errors)
|
||||
result['cmd'] = ' '.join(shlex_quote(arg) for arg in [cli] + args)
|
||||
result['stdout'] = to_native(stdout)
|
||||
result['stdout'] = to_native(stdout) if stdout is not None else ''
|
||||
result['stderr'] = to_native(stderr)
|
||||
result['rc'] = rc
|
||||
return True
|
||||
@@ -834,15 +834,17 @@ class BaseComposeManager(DockerBaseClass):
|
||||
|
||||
def list_images(self):
|
||||
args = self.get_base_args() + ['images', '--format', 'json']
|
||||
kwargs = dict(cwd=self.project_src, check_rc=not self.use_json_events)
|
||||
kwargs = dict(cwd=self.project_src, check_rc=not self.use_json_events, parse_empty_as_none=True)
|
||||
rc, images, stderr = self.client.call_cli_json(*args, **kwargs)
|
||||
if self.use_json_events and rc != 0:
|
||||
self._handle_failed_cli_call(args, rc, images, stderr)
|
||||
if images is None:
|
||||
return []
|
||||
if isinstance(images, dict):
|
||||
# Handle breaking change in Docker Compose 2.37.0; see
|
||||
# https://github.com/ansible-collections/community.docker/issues/1082
|
||||
# and https://github.com/docker/compose/issues/12916 for details
|
||||
images = list(images.values())
|
||||
return list(images.values())
|
||||
return images
|
||||
|
||||
def parse_events(self, stderr, dry_run=False, nonzero_rc=False):
|
||||
|
||||
Reference in New Issue
Block a user