From 9b00fd4ca17c98583523a2d1ec652eb3f62f7aff Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Wed, 21 Feb 2018 18:10:23 +1000 Subject: [PATCH] fetch: set fail_on_missing: True as default as per docs (#36469) * fetch: set fail_on_missing: True as default as per docs * Updated docs for fetch to say behaviour was changed in 2.5 and updated tests (cherry picked from commit df8a5d7a4fae12340823f8807f9436b6d4d337f7) --- lib/ansible/modules/files/fetch.py | 8 ++++---- lib/ansible/plugins/action/fetch.py | 2 +- test/integration/targets/fetch/tasks/main.yml | 12 ++++++++++++ test/integration/targets/win_fetch/tasks/main.yml | 14 +++++++++++++- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/files/fetch.py b/lib/ansible/modules/files/fetch.py index 540391842e..2ac8f47480 100644 --- a/lib/ansible/modules/files/fetch.py +++ b/lib/ansible/modules/files/fetch.py @@ -41,9 +41,9 @@ options: version_added: "1.1" description: - When set to 'yes', the task will fail if the remote file cannot be - read for any reason. Prior to Ansible-2.4, setting this would only fail + read for any reason. Prior to Ansible-2.5, setting this would only fail if the source file was missing. - - The default was changed to "yes" in Ansible-2.4. + - The default was changed to "yes" in Ansible-2.5. required: false choices: [ "yes", "no" ] default: "yes" @@ -73,8 +73,8 @@ notes: depending on the file size can consume all available memory on the remote or local hosts causing a C(MemoryError). Due to this it is advisable to run this module without C(become) whenever possible. - - Prior to Ansible-2.4 this module would not fail if reading the remote - file was impossible unless fail_on_missing was set. In Ansible-2.4+, + - Prior to Ansible-2.5 this module would not fail if reading the remote + file was impossible unless fail_on_missing was set. In Ansible-2.5+, playbook authors are encouraged to use fail_when or ignore_errors to get this ability. They may also explicitly set fail_on_missing to False to get the non-failing behaviour. diff --git a/lib/ansible/plugins/action/fetch.py b/lib/ansible/plugins/action/fetch.py index bc07d6a4fa..fbaf9926c5 100644 --- a/lib/ansible/plugins/action/fetch.py +++ b/lib/ansible/plugins/action/fetch.py @@ -54,7 +54,7 @@ class ActionModule(ActionBase): source = self._task.args.get('src', None) dest = self._task.args.get('dest', None) flat = boolean(self._task.args.get('flat'), strict=False) - fail_on_missing = boolean(self._task.args.get('fail_on_missing'), strict=False) + fail_on_missing = boolean(self._task.args.get('fail_on_missing', True), strict=False) validate_checksum = boolean(self._task.args.get('validate_checksum', self._task.args.get('validate_md5', True)), strict=False) diff --git a/test/integration/targets/fetch/tasks/main.yml b/test/integration/targets/fetch/tasks/main.yml index 17bf7ba0e9..d7ea3ea947 100644 --- a/test/integration/targets/fetch/tasks/main.yml +++ b/test/integration/targets/fetch/tasks/main.yml @@ -77,6 +77,18 @@ - "fetch_missing.msg" - "fetch_missing is not changed" +- name: attempt to fetch a non-existent file - fail on missing implicit + fetch: src={{ output_dir }}/doesnotexist dest={{ output_dir }}/fetched + register: fetch_missing_implicit + ignore_errors: true + +- name: check fetch missing with failure with implicit fail + assert: + that: + - "fetch_missing_implicit is failed" + - "fetch_missing_implicit.msg" + - "fetch_missing_implicit is not changed" + - name: attempt to fetch a directory - should not fail but return a message fetch: src={{ output_dir }} dest={{ output_dir }}/somedir fail_on_missing=False register: fetch_dir diff --git a/test/integration/targets/win_fetch/tasks/main.yml b/test/integration/targets/win_fetch/tasks/main.yml index 2849782127..5f5782c8ad 100644 --- a/test/integration/targets/win_fetch/tasks/main.yml +++ b/test/integration/targets/win_fetch/tasks/main.yml @@ -136,7 +136,7 @@ - "fetch_small_bs_stat.stat.checksum == fetch_small_bs.checksum" - name: attempt to fetch a non-existent file - do not fail on missing - fetch: src="C:/this_file_should_not_exist.txt" dest={{ host_output_dir }} + fetch: src="C:/this_file_should_not_exist.txt" dest={{ host_output_dir }} fail_on_missing=no register: fetch_missing_nofail - name: check fetch missing no fail result @@ -158,6 +158,18 @@ - "fetch_missing.msg" - "fetch_missing is not changed" +- name: attempt to fetch a non-existent file - fail on missing implicit + fetch: src="~/this_file_should_not_exist.txt" dest={{ host_output_dir }} + register: fetch_missing_implicit + ignore_errors: true + +- name: check fetch missing with failure on implicit + assert: + that: + - "fetch_missing_implicit is failed" + - "fetch_missing_implicit.msg" + - "fetch_missing_implicit is not changed" + - name: attempt to fetch a directory fetch: src="C:\\Windows" dest={{ host_output_dir }} register: fetch_dir