Repository: ansible/ansible

Issue:
--diff flag stopped producing the diff from file module
##### SUMMARY
In recent release candidates the `--diff` option stopped working (meaning that it became non-functional), this was tested for the file module.

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
ansible-playbook CLI
--diff CLI option

##### ANSIBLE VERSION
tested and confirmed bug in environments:
```
ansible --version
ansible 2.7.0.dev0
  config file = None
  configured module search path = [u'/Users/alancoding/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/alancoding/.virtualenvs/ansible/lib/python2.7/site-packages/ansible-2.7.0.dev0-py2.7.egg/ansible
  executable location = /Users/alancoding/.virtualenvs/ansible/bin/ansible
  python version = 2.7.11 (default, Oct 17 2016, 14:59:40) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
```

```
ansible --version
ansible 2.6.0rc3
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
```

##### CONFIGURATION
No output from `ansible-config dump --only-changed`

##### OS / ENVIRONMENT
tested as local action in CentOS container

```
cat /proc/version
Linux version 4.9.87-linuxkit-aufs (root@95fa5ec30613) (gcc version 6.4.0 (Alpine 6.4.0) ) #1 SMP Wed Mar 14 15:12:16 UTC 2018
```

installed via

```
rpm -Uvh https://releases.ansible.com/ansible/rpm/preview/epel-7-x86_64/ansible-2.6.0-0.1003.rc3.el7.ans.noarch.rpm
```

Also confirmed on Mac

##### STEPS TO REPRODUCE
playbook, `file.yml`
```yaml
---

- hosts: all
  gather_facts: false
  vars:
    file_name: '/tmp/test'
  tasks:
    - file:
        path: '{{file_name}}'
        state: touch

```

command:

```
ansible-playbook -i localhost, --connection local file.yml --diff
```

##### EXPECTED RESULTS
Result from 2.5.3

```
PLAY [all] **************************************************************************************************************************************************************************

TASK [file] *************************************************************************************************************************************************************************
--- before
+++ after
@@ -1,4 +1,4 @@
 {
     "path": "/tmp/test",
-    "state": "file"
+    "state": "touch"
 }

changed: [localhost]

PLAY RECAP **************************************************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0 
```

##### ACTUAL RESULTS

```
PLAY [all] **************************************************************************************************************************************************************************

TASK [file] *************************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP **************************************************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0   

```



Discussion:
Files identified in the description:
* [lib/ansible/playbook](https://github.com/ansible/ansible/blob/devel/lib/ansible/playbook)

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 --->
Source of the playbook https://github.com/jlaska/ansible-playbooks/blob/master/file.yml

@wenottingham this is a blocker for Tower, and has been seen in test systems.

I first thought this was the same as https://github.com/ansible/ansible/issues/34226, but has 2.4 on it, and it was working as of 2.5, so that makes it a recent regression, and the module is different anyway.
This was introduced in 4e2876be9f3e96a7573c8acaff80fe0cd07c5e4b

cc @abadger 

Resolving patch:
diff --git a/lib/ansible/modules/files/file.py b/lib/ansible/modules/files/file.py
--- a/lib/ansible/modules/files/file.py
+++ b/lib/ansible/modules/files/file.py
@@ -370,7 +370,7 @@ def execute_touch(path, follow):
             raise
 
     # Unfortunately, touch always changes the file because it updates file's timestamp
-    return {'dest': path, 'changed': True}
+    return {'dest': path, 'changed': True, 'diff': diff}
 
 
 def ensure_file_attributes(path, follow):


Test patch: