Repository: ansible/ansible

Issue:
validate_checksum parameter of fetch module is actually default to "no" does not match the document.
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
 - Documentation Report

##### COMPONENT NAME
fetch

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.3.0.0
  config file = /home/xufan/.ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Sep 28 2016, 15:46:00) [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
nothing

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->
anything

##### SUMMARY
<!--- Explain the problem briefly -->
In the ansible [document](http://docs.ansible.com/ansible/fetch_module.html) the validate_checksum is default set to yes. But actually is "no" in the [fetch.py](https://github.com/ansible/ansible/blob/v2.3.0.0-1/lib/ansible/plugins/action/fetch.py)

##### STEPS TO REPRODUCE
nothing

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Change the validate_checksum of document default to "no".

##### ACTUAL RESULTS
nothing



Discussion:
The module/action does look like it will default to false/no when not specified which doesn't match the docs. 

I'm not sure which is actually correct.
Docs are correct, code is wrong.  validate_checksum should default to True.
@abadger Thanks for your reply. I give a new pull request #23995

Resolving patch:
diff --git a/lib/ansible/plugins/action/fetch.py b/lib/ansible/plugins/action/fetch.py
--- a/lib/ansible/plugins/action/fetch.py
+++ b/lib/ansible/plugins/action/fetch.py
@@ -48,11 +48,15 @@ def run(self, tmp=None, task_vars=None):
         fail_on_missing   = boolean(self._task.args.get('fail_on_missing'))
         validate_checksum = boolean(self._task.args.get('validate_checksum', self._task.args.get('validate_md5', True)))
 
+        # validate_md5 is the deprecated way to specify validate_checksum
         if 'validate_md5' in self._task.args and 'validate_checksum' in self._task.args:
             result['failed'] = True
             result['msg'] = "validate_checksum and validate_md5 cannot both be specified"
             return result
 
+        if 'validate_md5' in self._task.args:
+            display.deprecated('Use validate_checksum instead of validate_md5', version='2.8')
+
         if source is None or dest is None:
             result['failed'] = True
             result['msg'] = "src and dest are required"


Test patch:
diff --git a/test/integration/targets/fetch/tasks/main.yml b/test/integration/targets/fetch/tasks/main.yml
--- a/test/integration/targets/fetch/tasks/main.yml
+++ b/test/integration/targets/fetch/tasks/main.yml
@@ -25,6 +25,13 @@
 
 - debug: var=fetched
 
+- name: Assert that we fetched correctly
+  assert:
+    that:
+      - 'fetched["changed"] == True'
+      - 'fetched["checksum"] == "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"'
+      - 'fetched["remote_checksum"] == "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"'
+
 # TODO: check the become and non-become forms of fetch because in one form we'll do
 # the get method of the connection plugin and in the become case we'll use the
 # fetch module.
@@ -38,6 +45,16 @@
     that:
       'diff.stdout == ""'
 
+- name: fetch a second time to show idempotence
+  fetch: src={{ output_dir }}/orig dest={{ output_dir }}/fetched
+  register: fetched
+
+- name: Assert that the file was not fetched the second time
+  assert:
+    that:
+      - 'fetched["changed"] == False'
+      - 'fetched["checksum"] == "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"'
+
 - name: attempt to fetch a non-existent file - do not fail on missing
   fetch: src={{ output_dir }}/doesnotexist dest={{ output_dir }}/fetched
   register: fetch_missing_nofail