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 00000000000..52a55dc8733 --- /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/changelogs/fragments/56940-docker_image-fail.yml b/changelogs/fragments/56940-docker_image-fail.yml new file mode 100644 index 00000000000..117d455a7de --- /dev/null +++ b/changelogs/fragments/56940-docker_image-fail.yml @@ -0,0 +1,2 @@ +bugfixes: +- "docker_image - module failed when ``source: build`` was set but ``build.path`` options not specified." diff --git a/lib/ansible/modules/cloud/docker/docker_image.py b/lib/ansible/modules/cloud/docker/docker_image.py index 48e867a8ab3..08b2871fbd8 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,14 +879,14 @@ 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 ' 'has been renamed and will be removed in Ansible 2.12.' % (build_option, option, option)) if client.module.params['source'] == 'build': if (not client.module.params['build'] or not client.module.params['build'].get('path')): - client.module.fail('If "source" is set to "build", the "build.path" option must be specified.') + client.fail('If "source" is set to "build", the "build.path" option must be specified.') if client.module.params['build'].get('pull') is None: client.module.warn("The default for build.pull is currently 'yes', but will be changed to 'no' in Ansible 2.12. " "Please set build.pull explicitly to the value you need.") diff --git a/test/integration/targets/docker_image/tasks/tests/old-options.yml b/test/integration/targets/docker_image/tasks/tests/old-options.yml new file mode 100644 index 00000000000..5571cf96fab --- /dev/null +++ b/test/integration/targets/docker_image/tasks/tests/old-options.yml @@ -0,0 +1,48 @@ +--- +- name: Registering image name + set_fact: + iname: "{{ name_prefix ~ '-old-options' }}" + +- name: Registering image name + set_fact: + inames: "{{ inames }} + [iname]" + +#################################################################### +## build ########################################################### +#################################################################### + +- name: build with old-style options + docker_image: + name: "{{ iname }}" + path: "{{ role_path }}/files" + dockerfile: Dockerfile + http_timeout: 60 + nocache: yes + pull: no + rm: no + buildargs: + TEST1: val1 + TEST2: val2 + TEST3: "True" + container_limits: + memory: 5000000 + memswap: 7000000 + source: build + register: build + +- name: cleanup + docker_image: + name: "{{ iname }}" + state: absent + force_absent: yes + +- assert: + that: + - '"Please specify build.container_limits instead of container_limits. The container_limits option has been renamed and will be removed in Ansible 2.12." in build.warnings' + - '"Please specify build.dockerfile instead of dockerfile. The dockerfile option has been renamed and will be removed in Ansible 2.12." in build.warnings' + - '"Please specify build.http_timeout instead of http_timeout. The http_timeout option has been renamed and will be removed in Ansible 2.12." in build.warnings' + - '"Please specify build.nocache instead of nocache. The nocache option has been renamed and will be removed in Ansible 2.12." in build.warnings' + - '"Please specify build.path instead of path. The path option has been renamed and will be removed in Ansible 2.12." in build.warnings' + - '"Please specify build.pull instead of pull. The pull option has been renamed and will be removed in Ansible 2.12." in build.warnings' + - '"Please specify build.rm instead of rm. The rm option has been renamed and will be removed in Ansible 2.12." in build.warnings' + - '"Please specify build.args instead of buildargs. The buildargs option has been renamed and will be removed in Ansible 2.12." in build.warnings'