You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update the file module to return a list of diffs when recursively setting file attributes and recursively creating parent directories.
ISSUE TYPE
Bugfix Pull Request
ADDITIONAL INFORMATION
In the following example, ansible fails to report that it created multiple direectories, fails to report that it modified file attributes, and then misleads the user into thinking it modified fewer file attributes than it actually did.
example playbook:
Details
- name: playhosts: localhostgather_facts: falsetasks:
- name: create directory with same permsansible.builtin.file:
path: /tmp/foo/barstate: directorymode: "0755"diff: true
- name: create directory with different permsansible.builtin.file:
path: /tmp/fu/barstate: directorymode: "0770"diff: true
- name: create file with different permsansible.builtin.file:
path: "{{ item }}"state: touchmode: "0770"diff: falseloop:
- /tmp/foo/bar/file1
- /tmp/foo/bar/file2
- /tmp/fu/bar/file1
- /tmp/fu/bar/file2
- name: recursively modify permissions on directory with same permsansible.builtin.file:
path: /tmp/foo/barmode: "0755"recurse: truediff: true
- name: recursively modify permissions on directory with different permsansible.builtin.file:
path: /tmp/fu/barmode: "0755"recurse: truediff: true
playbook output before:
Details
PLAY [play] **********************************************************************************TASK [create directory with same perms] ******************************************************--- before+++ after@@ -1,3 +1,3 @@-mode: '0775'+mode: '0755' path: /tmp/foo/bar-state: absent+state: directorychanged: [localhost]TASK [create directory with different perms] *************************************************--- before+++ after@@ -1,3 +1,3 @@-mode: '0775'+mode: '0770' path: /tmp/fu/bar-state: absent+state: directorychanged: [localhost]TASK [create file with different perms] ******************************************************changed: [localhost] => (item=/tmp/foo/bar/file1)changed: [localhost] => (item=/tmp/foo/bar/file2)changed: [localhost] => (item=/tmp/fu/bar/file1)changed: [localhost] => (item=/tmp/fu/bar/file2)TASK [recursively modify permissions on directory with same perms] ***************************changed: [localhost]TASK [recursively modify permissions on directory with different perms] **********************--- before+++ after@@ -1,2 +1,2 @@-mode: '0770'+mode: '0755' path: /tmp/fu/barchanged: [localhost]PLAY RECAP ***********************************************************************************localhost : ok=5 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
The test ansible-test sanity --test mypy --python 3.8 [explain] failed with 7 errors:
lib/ansible/modules/file.py:344:89: assignment: Incompatible default for argument "diff_list" (default has type "None", argument has type "List[Any]")
lib/ansible/modules/file.py:355:32: attr-defined: "None" has no attribute "set_fs_attributes_if_different"
lib/ansible/modules/file.py:362:32: attr-defined: "None" has no attribute "set_fs_attributes_if_different"
lib/ansible/modules/file.py:376:40: attr-defined: "None" has no attribute "set_fs_attributes_if_different"
lib/ansible/modules/file.py:390:81: assignment: Incompatible default for argument "diff_list" (default has type "None", argument has type "List[Any]")
lib/ansible/modules/file.py:400:16: attr-defined: "None" has no attribute "check_mode"
lib/ansible/modules/file.py:411:9: attr-defined: "None" has no attribute "set_fs_attributes_if_different"
The test ansible-test sanity --test mypy --python 3.9 [explain] failed with 7 errors:
lib/ansible/modules/file.py:344:89: assignment: Incompatible default for argument "diff_list" (default has type "None", argument has type "list[Any]")
lib/ansible/modules/file.py:355:32: attr-defined: "None" has no attribute "set_fs_attributes_if_different"
lib/ansible/modules/file.py:362:32: attr-defined: "None" has no attribute "set_fs_attributes_if_different"
lib/ansible/modules/file.py:376:40: attr-defined: "None" has no attribute "set_fs_attributes_if_different"
lib/ansible/modules/file.py:390:81: assignment: Incompatible default for argument "diff_list" (default has type "None", argument has type "list[Any]")
lib/ansible/modules/file.py:400:16: attr-defined: "None" has no attribute "check_mode"
lib/ansible/modules/file.py:411:9: attr-defined: "None" has no attribute "set_fs_attributes_if_different"
ansibot
removed
needs_revision
This PR fails CI tests or a maintainer has requested a review/revision of the PR.
ci_verified
Changes made in this PR are causing tests to fail.
labels
Jun 13, 2024
The copy module integration tests caught two bugs in my code that the file module integration tests did not: the first occurred when creating a directory with a relative path, the second occured when trying to create a directory that already exists creating a directory with a path ending with a slash
ansibot
added
the
stale_ci
This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
label
Jul 2, 2024
The reason will be displayed to describe this comment to others. Learn more.
This is a rather invasive change to the file module. If you can reduce the number of lines you've modified, this would be significantly easier to review.
ansibot
added
needs_revision
This PR fails CI tests or a maintainer has requested a review/revision of the PR.
and removed
stale_ci
This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
labels
Nov 15, 2024
ansibot
removed
needs_revision
This PR fails CI tests or a maintainer has requested a review/revision of the PR.
ci_verified
Changes made in this PR are causing tests to fail.
labels
Nov 15, 2024
ansibot
added
the
stale_ci
This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
label
Dec 2, 2024
This is a rather invasive change to the file module. If you can reduce the number of lines you've modified, this would be significantly easier to review.
@s-hertel I didn't say anything at the time but I did reduce the number of lines. I reduced it some more just now.
ansibot
removed
the
stale_ci
This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
label
Jun 26, 2025
ansibot
added
the
stale_ci
This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
label
Jul 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugThis issue/PR relates to a bug.has_issuemoduleThis issue/PR relates to a module.stale_ciThis PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
5 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
Fixes #83434
Fixes #83435
Update the
filemodule to return a list of diffs when recursively setting file attributes and recursively creating parent directories.ISSUE TYPE
ADDITIONAL INFORMATION
In the following example, ansible fails to report that it created multiple direectories, fails to report that it modified file attributes, and then misleads the user into thinking it modified fewer file attributes than it actually did.
example playbook:
Details
playbook output before:
Details
playbook output after:
Details