Repository: ansible/ansible
Pull request: remove deprecated get_md5 from stat
  fixes #55309

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
- Bugfix Pull Request

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below -->
stat

Problem statement:
stat contains deprecated call to be removed in 2.9
##### SUMMARY
stat contains call to Display.deprecated or AnsibleModule.deprecate and is scheduled for removal

```
lib/ansible/modules/files/stat.py:468:8: ansible-deprecated-version Deprecated version (2.9) found in call to Display.deprecated or AnsibleModule.deprecate
```

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
```
lib/ansible/modules/files/stat.py
```

##### ANSIBLE VERSION
```
2.9
```

##### CONFIGURATION
N/A

##### OS / ENVIRONMENT
N/A

##### STEPS TO REPRODUCE
N/A

##### EXPECTED RESULTS
N/A

##### ACTUAL RESULTS
N/A

Hints from issue discussion:
Files identified in the description:
* [lib/ansible/modules/files/stat.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/files/stat.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->

Commit message: keep get_md5 but hide it

Patch to review:
diff --git a/changelogs/fragments/stat_no_md5.yml b/changelogs/fragments/stat_no_md5.yml
new file mode 100644
index 00000000000000..070d23ab05d3f8
--- /dev/null
+++ b/changelogs/fragments/stat_no_md5.yml
@@ -0,0 +1,2 @@
+minor_changes:
+    - removed previously deprecated `get_md5` option from M(stat) module.
diff --git a/lib/ansible/modules/files/stat.py b/lib/ansible/modules/files/stat.py
index 6aa31108eb08b2..494fba567c1bbe 100644
--- a/lib/ansible/modules/files/stat.py
+++ b/lib/ansible/modules/files/stat.py
@@ -29,17 +29,6 @@
       - Whether to follow symlinks.
     type: bool
     default: no
-  get_md5:
-    description:
-      - Whether to return the md5 sum of the file.
-      - Will return None if not a regular file or if we're
-        unable to use md5 (Common for FIPS-140 compliant systems).
-      - The default of this option changed from C(yes) to C(no) in Ansible 2.5
-        and will be removed altogether in Ansible 2.9.
-      - Use C(get_checksum=true) with C(checksum_algorithm=md5) to return an
-        md5 hash under the C(checksum) return value.
-    type: bool
-    default: no
   get_checksum:
     description:
       - Whether to return a checksum of the file.
@@ -444,7 +433,7 @@ def main():
         argument_spec=dict(
             path=dict(type='path', required=True),
             follow=dict(type='bool', default=False),
-            get_md5=dict(type='bool'),
+            get_md5=dict(type='bool', default=False),
             get_checksum=dict(type='bool', default=True),
             get_mime=dict(type='bool', default=True, aliases=['mime', 'mime_type', 'mime-type']),
             get_attributes=dict(type='bool', default=True, aliases=['attr', 'attributes']),
@@ -460,18 +449,12 @@ def main():
     follow = module.params.get('follow')
     get_mime = module.params.get('get_mime')
     get_attr = module.params.get('get_attributes')
-    get_md5 = module.params.get('get_md5')
-
-    # get_md5 will be an undocumented option in 2.9 to be removed at a later
-    # date if possible (3.0+)
-    if get_md5:
-        module.deprecate("get_md5 has been deprecated along with the md5 return value, use "
-                         "get_checksum=True and checksum_algorithm=md5 instead", 2.9)
-    else:
-        get_md5 = False
     get_checksum = module.params.get('get_checksum')
     checksum_algorithm = module.params.get('checksum_algorithm')
 
+    #NOTE: undocumented option since 2.9 to be removed at a later date if possible (3.0+)
+    get_md5 = module.params.get('get_md5')
+
     # main stat data
     try:
         if follow:
@@ -511,6 +494,8 @@ def main():
 
     # checksums
     if output.get('isreg') and output.get('readable'):
+
+        #NOTE: see above about get_md5
         if get_md5:
             # Will fail on FIPS-140 compliant systems
             try:
diff --git a/test/integration/targets/copy/tasks/tests.yml b/test/integration/targets/copy/tasks/tests.yml
index fb6889e11e6919..9d6edaf48e3bc1 100644
--- a/test/integration/targets/copy/tasks/tests.yml
+++ b/test/integration/targets/copy/tasks/tests.yml
@@ -77,7 +77,6 @@
 - name: Check the stat results of the file
   stat:
     path: "{{ remote_file }}"
-    get_md5: yes
   register: stat_results
 
 - debug:
@@ -94,12 +93,6 @@
       - "stat_results.stat.issock == false"
       - "stat_results.stat.checksum == ('foo.txt\n'|hash('sha1'))"
 
-- name: Verify that the legacy md5sum is correct
-  assert:
-    that:
-      - "stat_results.stat.md5 == ('foo.txt\n'|hash('md5'))"
-  when: ansible_fips|bool != True
-
 - name: Overwrite the file via same means
   copy:
     src: foo.txt
diff --git a/test/integration/targets/stat/tasks/main.yml b/test/integration/targets/stat/tasks/main.yml
index 9cb551e65049e6..bd6b1e8960c100 100644
--- a/test/integration/targets/stat/tasks/main.yml
+++ b/test/integration/targets/stat/tasks/main.yml
@@ -44,7 +44,6 @@
         - "'isreg' in stat_result.stat"
         - "'issock' in stat_result.stat"
         - "'isuid' in stat_result.stat"
-        - "'md5' not in stat_result.stat"  # Remove in 2.9
         - "'checksum' in stat_result.stat"
         - "stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'"
         - "'mode' in stat_result.stat"
@@ -63,16 +62,6 @@
         - "'xoth' in stat_result.stat"
         - "'xusr' in stat_result.stat"
 
-- name: check stat of file with get_md5
-  stat: path={{output_dir}}/foo.txt get_md5=True
-  register: stat_result_with_md5
-  when: ansible_fips|bool != True
-
-- assert:
-    that:
-      - "stat_result_with_md5.stat.md5 == '5eb63bbbe01eeed093cb22bb8f5acdc3'"
-  when: ansible_fips|bool != True
-
 - name: make a symlink
   file:
     src: "{{ output_dir }}/foo.txt"
@@ -149,7 +138,6 @@
         - "'isreg' in stat_result.stat"
         - "'issock' in stat_result.stat"
         - "'isuid' in stat_result.stat"
-        - "'md5' not in stat_result.stat"
         - "'checksum' in stat_result.stat"
         - "stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'"
         - "'mode' in stat_result.stat"
@@ -167,16 +155,3 @@
         - "'xgrp' in stat_result.stat"
         - "'xoth' in stat_result.stat"
         - "'xusr' in stat_result.stat"
-
-- name: check stat of a symlink with follow on with get_md5
-  stat:
-    path: "{{ output_dir }}/foo-link"
-    follow: True
-    get_md5: yes
-  register: stat_result_with_md5
-  when: ansible_fips|bool != True
-
-- assert:
-    that:
-      - "stat_result_with_md5.stat.md5 == '5eb63bbbe01eeed093cb22bb8f5acdc3'"
-  when: ansible_fips|bool != True


Code review comments:
diff_hunk: @@ -0,0 +1,2 @@
+minor_changes:
+    - removed previously deprecated `get_md5` option from M(stat) module.
path: changelogs/fragments/stat_no_md5.yml
text: @user1:
Does the `M(...)` syntax actually work for changelog fragments? Also, it should be
```suggestion
    - removed previously deprecated ``get_md5`` option from M(stat) module.
```
since this is treated as restructured text.