summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConner Crosby <cavcrosby@gmail.com>2024-10-25 20:32:11 +0200
committerGitHub <noreply@github.com>2024-10-25 20:32:11 +0200
commitd662a8d0883882c6ada7284a33c3eb3607753d24 (patch)
tree2975c0888610b2f3666537ac8e83a980ca6017b8
parentdocs: print deprecation collection name (#84126) (diff)
downloadansible-d662a8d0883882c6ada7284a33c3eb3607753d24.tar.xz
ansible-d662a8d0883882c6ada7284a33c3eb3607753d24.zip
Enable file module to disable diff_mode (#83700)
Several tasks within the modification_time.yml and state_link.yml task lists have explicitly enabled diff_mode because these tests previously assumed a diff attribute would always be returned from the file module.
-rw-r--r--changelogs/fragments/83700-enable-file-disable-diff.yml2
-rw-r--r--lib/ansible/modules/file.py3
-rw-r--r--test/integration/targets/file/tasks/diff.yml44
-rw-r--r--test/integration/targets/file/tasks/main.yml3
-rw-r--r--test/integration/targets/file/tasks/modification_time.yml3
-rw-r--r--test/integration/targets/file/tasks/state_link.yml1
6 files changed, 56 insertions, 0 deletions
diff --git a/changelogs/fragments/83700-enable-file-disable-diff.yml b/changelogs/fragments/83700-enable-file-disable-diff.yml
new file mode 100644
index 0000000000..4fdc9feb4c
--- /dev/null
+++ b/changelogs/fragments/83700-enable-file-disable-diff.yml
@@ -0,0 +1,2 @@
+minor_changes:
+ - file - enable file module to disable diff_mode (https://github.com/ansible/ansible/issues/80817).
diff --git a/lib/ansible/modules/file.py b/lib/ansible/modules/file.py
index f4761fc492..b79eca5888 100644
--- a/lib/ansible/modules/file.py
+++ b/lib/ansible/modules/file.py
@@ -1007,6 +1007,9 @@ def main():
elif state == 'absent':
result = ensure_absent(path)
+ if not module._diff:
+ result.pop('diff', None)
+
module.exit_json(**result)
diff --git a/test/integration/targets/file/tasks/diff.yml b/test/integration/targets/file/tasks/diff.yml
new file mode 100644
index 0000000000..a5246c5d1b
--- /dev/null
+++ b/test/integration/targets/file/tasks/diff.yml
@@ -0,0 +1,44 @@
+# file module tests for diff being returned in results
+
+- name: Initialize the test output dir
+ import_tasks: initialize.yml
+
+- name: Create an empty file
+ file:
+ state: touch
+ mode: "755"
+ path: "{{ remote_tmp_dir_test }}/foobar.txt"
+ register: temp_file
+
+- name: Confirm diff was not returned in results
+ assert:
+ that:
+ - temp_file.diff is not defined
+
+- name: Toggle permissions on said empty file
+ file:
+ state: file
+ mode: "644"
+ path: "{{ temp_file.dest }}"
+ register: temp_file
+ diff: true
+
+- name: Confirm diff was returned in results
+ assert:
+ that:
+ - temp_file.diff is defined
+
+- name: Toggle permissions on said empty file...again
+ file:
+ state: file
+ mode: "755"
+ path: "{{ temp_file.path }}"
+ register: temp_file
+ diff: false
+ environment:
+ ANSIBLE_DIFF_ALWAYS: True
+
+- name: Confirm diff was not returned in results
+ assert:
+ that:
+ - temp_file.diff is not defined
diff --git a/test/integration/targets/file/tasks/main.yml b/test/integration/targets/file/tasks/main.yml
index 8e14618118..158fc3ec59 100644
--- a/test/integration/targets/file/tasks/main.yml
+++ b/test/integration/targets/file/tasks/main.yml
@@ -55,6 +55,9 @@
- name: Test modification time
import_tasks: modification_time.yml
+- name: Test diff_mode
+ import_tasks: diff.yml
+
# These tests need to be organized by state parameter into separate files later
- name: verify that we are checking a file and it is present
diff --git a/test/integration/targets/file/tasks/modification_time.yml b/test/integration/targets/file/tasks/modification_time.yml
index daec03627c..7c6c23d374 100644
--- a/test/integration/targets/file/tasks/modification_time.yml
+++ b/test/integration/targets/file/tasks/modification_time.yml
@@ -19,6 +19,7 @@
modification_time_format: "%Y%m%d%H%M.%S"
check_mode: true
register: file_change_check_mode
+ diff: true
- name: Re-stat the file
stat:
@@ -41,6 +42,7 @@
modification_time: "{{ modification_timestamp }}"
modification_time_format: "%Y%m%d%H%M.%S"
register: file_change_no_check_mode
+ diff: true
- name: Stat of the file after the change
stat:
@@ -61,6 +63,7 @@
modification_time: "{{ modification_timestamp }}"
modification_time_format: "%Y%m%d%H%M.%S"
register: file_change_no_check_mode_second
+ diff: true
- name: Confirm no changes made registered
assert:
diff --git a/test/integration/targets/file/tasks/state_link.yml b/test/integration/targets/file/tasks/state_link.yml
index 374e97e25f..1927f5e0ac 100644
--- a/test/integration/targets/file/tasks/state_link.yml
+++ b/test/integration/targets/file/tasks/state_link.yml
@@ -29,6 +29,7 @@
- name: change soft link to relative
file: src={{output_file|basename}} dest={{remote_tmp_dir_test}}/soft.txt state=link
register: file2_result
+ diff: true
- name: Get stat info for the link
stat: