From 50d56ca89de26317c41c4fb1a777fd7ccdc025a2 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 18 Mar 2019 06:34:07 +0100 Subject: [PATCH] docker_image: stop pulling by default on build (#53911) * Prepare to change default of build.pull from yes to no in Ansible 2.12. * Specify build.pull. * Add changelog. * Fix bad indent. --- .../53911-docker_image-build-pull-default.yml | 2 ++ .../modules/cloud/docker/docker_image.py | 20 +++++++++++-------- .../docker_image/tasks/tests/options.yml | 14 ++++++++++++- 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/53911-docker_image-build-pull-default.yml diff --git a/changelogs/fragments/53911-docker_image-build-pull-default.yml b/changelogs/fragments/53911-docker_image-build-pull-default.yml new file mode 100644 index 00000000000..8402b963b9c --- /dev/null +++ b/changelogs/fragments/53911-docker_image-build-pull-default.yml @@ -0,0 +1,2 @@ +minor_changes: +- "docker_image - the default for ``build.pull`` will change from ``yes`` to ``no`` in Ansible 2.12. Please update your playbooks/roles now." diff --git a/lib/ansible/modules/cloud/docker/docker_image.py b/lib/ansible/modules/cloud/docker/docker_image.py index d1d1776abbb..94b7bb5adc6 100644 --- a/lib/ansible/modules/cloud/docker/docker_image.py +++ b/lib/ansible/modules/cloud/docker/docker_image.py @@ -75,8 +75,8 @@ options: pull: description: - When building an image downloads any updates to the FROM image in Dockerfile. + - The default is currently C(yes). This will change to C(no) in Ansible 2.12. type: bool - default: yes rm: description: - Remove intermediate containers after build. @@ -200,8 +200,8 @@ options: description: - When building an image downloads any updates to the FROM image in Dockerfile. - Please use I(build.pull) instead. This option will be removed in Ansible 2.12. + - The default is currently C(yes). This will change to C(no) in Ansible 2.12. type: bool - default: yes version_added: "2.1" push: description: @@ -773,7 +773,7 @@ def main(): network=dict(type='str'), nocache=dict(type='bool', default=False), path=dict(type='path', required=True), - pull=dict(type='bool', default=True), + pull=dict(type='bool'), rm=dict(type='bool', default=True), args=dict(type='dict'), )), @@ -794,7 +794,7 @@ def main(): name=dict(type='str', required=True), nocache=dict(type='bool', default=False, removedin_version='2.12'), path=dict(type='path', aliases=['build_path'], removedin_version='2.12'), - pull=dict(type='bool', default=True, removedin_version='2.12'), + pull=dict(type='bool', removedin_version='2.12'), push=dict(type='bool', default=False), repository=dict(type='str'), rm=dict(type='bool', default=True, removedin_version='2.12'), @@ -851,7 +851,7 @@ def main(): ) for option, build_option in build_options.items(): default_value = None - if option in ('pull', 'rm'): + if option in ('rm', ): default_value = True elif option in ('nocache', ): default_value = False @@ -863,9 +863,13 @@ def main(): 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' and \ - (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.') + 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.') + if client.module.params['build']['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.") + client.module.params['build']['pull'] = True # TODO: change to False in Ansible 2.12 if client.module.params['state'] == 'present' and client.module.params['source'] is None: # Autodetection. To be removed in Ansible 2.12. diff --git a/test/integration/targets/docker_image/tasks/tests/options.yml b/test/integration/targets/docker_image/tasks/tests/options.yml index 741b748fc46..a46b531da6f 100644 --- a/test/integration/targets/docker_image/tasks/tests/options.yml +++ b/test/integration/targets/docker_image/tasks/tests/options.yml @@ -21,6 +21,7 @@ TEST1: val1 TEST2: val2 TEST3: "True" + pull: no source: build register: buildargs_1 @@ -33,6 +34,7 @@ TEST1: val1 TEST2: val2 TEST3: "True" + pull: no source: build register: buildargs_2 @@ -65,6 +67,7 @@ path: "{{ role_path }}/files" container_limits: memory: 4000 + pull: no source: build ignore_errors: yes register: container_limits_1 @@ -77,6 +80,7 @@ container_limits: memory: 5000000 memswap: 7000000 + pull: no source: build register: container_limits_2 @@ -107,6 +111,7 @@ build: path: "{{ role_path }}/files" dockerfile: "MyDockerfile" + pull: no source: build register: dockerfile_1 @@ -136,6 +141,7 @@ name: "{{ iname }}" build: path: "{{ role_path }}/files" + pull: no repository: "{{ registry_address }}/test/{{ iname }}" source: build register: repository_1 @@ -145,6 +151,7 @@ name: "{{ iname }}" build: path: "{{ role_path }}/files" + pull: no repository: "{{ registry_address }}/test/{{ iname }}" source: build register: repository_2 @@ -178,6 +185,7 @@ name: "{{ iname }}" build: path: "{{ role_path }}/files" + pull: no source: build - name: force (changed) @@ -186,6 +194,7 @@ build: path: "{{ role_path }}/files" dockerfile: "MyDockerfile" + pull: no source: build force_source: yes register: force_1 @@ -196,6 +205,7 @@ build: path: "{{ role_path }}/files" dockerfile: "MyDockerfile" + pull: no source: build force_source: yes register: force_2 @@ -257,6 +267,7 @@ name: "{{ iname }}" build: path: "{{ role_path }}/files" + pull: no source: build register: path_1 @@ -264,7 +275,8 @@ docker_image: name: "{{ iname }}" build: - path: "{{ role_path }}/files" + path: "{{ role_path }}/files" + pull: no source: build register: path_2