diff --git a/changelogs/fragments/56610-docker_image-fix-oldstyle-defaults.yml b/changelogs/fragments/56610-docker_image-fix-oldstyle-defaults.yml new file mode 100644 index 0000000000..52a55dc873 --- /dev/null +++ b/changelogs/fragments/56610-docker_image-fix-oldstyle-defaults.yml @@ -0,0 +1,3 @@ +bugfixes: +- "docker_image - if ``nocache`` set to ``yes`` but not ``build.nocache``, the module failed." +- "docker_image - if ``build`` was not specified, the wrong default for ``build.rm`` is used." diff --git a/lib/ansible/modules/cloud/docker/docker_image.py b/lib/ansible/modules/cloud/docker/docker_image.py index 48e867a8ab..201c5b53c9 100644 --- a/lib/ansible/modules/cloud/docker/docker_image.py +++ b/lib/ansible/modules/cloud/docker/docker_image.py @@ -453,11 +453,11 @@ class ImageManager(DockerBaseClass): self.load_path = parameters.get('load_path') self.name = parameters.get('name') self.network = build.get('network') - self.nocache = build.get('nocache') + self.nocache = build.get('nocache', False) self.build_path = build.get('path') self.pull = build.get('pull') self.repository = parameters.get('repository') - self.rm = build.get('rm') + self.rm = build.get('rm', True) self.state = parameters.get('state') self.tag = parameters.get('tag') self.http_timeout = build.get('http_timeout') @@ -879,7 +879,7 @@ def main(): if client.module.params[option] != default_value: if client.module.params['build'] is None: client.module.params['build'] = dict() - if client.module.params['build'].get(build_option) != default_value: + if client.module.params['build'].get(build_option, default_value) != default_value: client.fail('Cannot specify both %s and build.%s!' % (option, build_option)) client.module.params['build'][build_option] = client.module.params[option] client.module.warn('Please specify build.%s instead of %s. The %s option '