Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible.builtin.file diff could not be disabled #80817

Open
1 task done
F-PMOR opened this issue May 17, 2023 · 4 comments
Open
1 task done

ansible.builtin.file diff could not be disabled #80817

F-PMOR opened this issue May 17, 2023 · 4 comments
Labels
affects_2.16 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation

Comments

@F-PMOR
Copy link

F-PMOR commented May 17, 2023

Summary

I'm trying to desactivate diff in ansible.builtin.file task like below while using the diff_mode (ansible-playbook playbook.yml --diff) :

- name: "Create Folder ../artifacts/{{ inventory_hostname }}/ if not exist"
  ansible.builtin.file:
    path: "../artifacts/{{ inventory_hostname }}"
    mode: 0755
    state: directory
  delegate_to: localhost
  diff: false

The option "diff: false" seams not beeing implemented in file module.

The output is :

TASK [orange.vpn : Create Folder ../artifacts/NEXUS-93180-1/ if not exist] **************************************************************************************************************************************************************************************************************************************************************
--- before
+++ after
@@ -1,4 +1,4 @@
 {
-    "mode": "0777",
+    "mode": "0755",
     "path": "../artifacts/NEXUS-93180-1"
 }

It should be :

TASK [orange.vpn : Create Folder ../artifacts/NEXUS-93180-1/ if not exist] **************************************************************************************************************************************************************************************************************************************************************
changed: [NEXUS-93180-1 -> localhost]

Issue Type

Feature Idea

Component Name

ansible.builtin.file

Additional Information

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented May 17, 2023

Files identified in the description:

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

click here for bot help

@ansibot ansibot added affects_2.16 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels May 17, 2023
@bcoca
Copy link
Member

bcoca commented May 17, 2023

From the docs in the file module:

    diff_mode:
        details: permissions and ownership will be shown but file contents on absent/touch will not.
        support: partial

The file module always returns those differences and does not respect diff mode setting, hence the 'partial' support.

@bcoca
Copy link
Member

bcoca commented May 17, 2023

but implementing the feature should not be too hard

diff --git a/lib/ansible/modules/file.py b/lib/ansible/modules/file.py
index 72b510c3ca..6c55ff70c8 100644
--- a/lib/ansible/modules/file.py
+++ b/lib/ansible/modules/file.py
@@ -980,6 +980,9 @@ def main():
     elif state == 'absent':
         result = ensure_absent(path)

+    if not module.diff_mode:
+        result.pop('diff')
+
     module.exit_json(**result)

@bcoca bcoca added P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels May 18, 2023
@nodiscc
Copy link

nodiscc commented Sep 5, 2023

I'd also like to see this implemented/fixed (is the patch above sufficient?), as the file module can be extremely verbose and clutter logs with state: absent on directories containing many files/subdirectories.

The only alternative currently available to prevent this, is to set no_log: True for the task, but it may hide useful information.

nodiscc added a commit to nodiscc/xsrv that referenced this issue Sep 5, 2023
…e excessively verbose diffs when using diff mode

- no_log: yes hides actual error messages while diff: no does not
- diff: no does not work to silence large diffs from the file module yet (ansible/ansible#80817)
nodiscc added a commit to nodiscc/xsrv that referenced this issue Sep 22, 2023
…e excessively verbose diffs when using diff mode

- no_log: yes hides actual error messages while diff: no does not
- diff: no does not work to silence large diffs from the file module yet (ansible/ansible#80817)
nodiscc added a commit to nodiscc/xsrv that referenced this issue Oct 30, 2023
…e excessively verbose diffs when using diff mode

- no_log: yes hides actual error messages while diff: no does not
- diff: no does not work to silence large diffs from the file module yet (ansible/ansible#80817)
nodiscc added a commit to nodiscc/xsrv that referenced this issue Dec 12, 2023
…e excessively verbose diffs when using diff mode

- no_log: yes hides actual error messages while diff: no does not
- diff: no does not work to silence large diffs from the file module yet (ansible/ansible#80817)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.16 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation
Projects
None yet
Development

No branches or pull requests

4 participants