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
angelavuong opened this issue
Jan 12, 2023
· 4 comments
Labels
affects_2.9This issue/PR affects Ansible v2.9bugThis issue/PR relates to a bug.has_prThis issue has an associated PR.moduleThis issue/PR relates to a module.P3Priority 3 - Approved, No Time LimitationverifiedThis issue has been verified/reproduced by maintainer
When using the copy module with remote_src: true, I'm observing unexpected behavior where the pre-existing files' ownership in the destination folder gets modified by the playbook:
Before:
[student@server-1 tmp]$ ll filedest/
total 4
-rw-rw-r--. 1 student student 15 Jan 6 15:04 leavemebe.txt
[root@server-1 ~]# ll /tmp/filesrc
total 4
-rw-rw-r--. 1 student student 10 Jan 6 15:04 copyme.txt
[root@server-1 ~]# ll /tmp/filedest/
total 8
-rw-r--r--. 1 root root 10 Jan 6 15:27 copyme.txt
-rw-rw-r--. 1 root root 15 Jan 6 15:04 leavemebe.txt
This behavior only happens with using remote_src: true. When running the copy module on the same Ansible host, this behavior does not occur.
Expected Results
I expected the copy module to only modify the file ownership of the copied files (copyme.txt) and not the pre-existing files' ownerships in the destination directory (leavemebe.txt).
Actual Results
We can see that the playbook changed both the copied files (copyme.txt) and existing files (leavemebe.txt)'s ownership to root:root in the destination directory.
[root@server-1 ~]# ll /tmp/filedest/
total 8
-rw-r--r--. 1 root root 10 Jan 6 15:27 copyme.txt
-rw-rw-r--. 1 root root 15 Jan 6 15:04 leavemebe.txt
Code of Conduct
I agree to follow the Ansible Code of Conduct
The text was updated successfully, but these errors were encountered:
jborean93
added
P3
Priority 3 - Approved, No Time Limitation
verified
This issue has been verified/reproduced by maintainer
and removed
needs_triage
Needs a first human triage before being processed.
labels
Jan 12, 2023
Effectively as of now, the module knows what files it need copied through its use of filecmp.dircmp. However, these lists are effectively thrown out, and at the end the module does a recursive os.walk across the dest dir, and sets the perms on everything, not just the files the module was to concern itself with.
We would need to track all of the files that needed to be copied, as well as those that already existed but didn't need to be copied because they match, and then only set file attributes/owner/etc on that list.
A quick filecmp.dircmp(src, dest).left_list might be sufficient instead of tracking everything across multiple function calls.
In the current structure, I suspect we actually need to track what files are changed because of the diff files. If a common file is exactly the same between source and destination, then we shouldn't change the ownership as well. However, since it appears in the left_list, I think the ownership will also get changed. Do you think maybe it is easier instead to change the ownership as we copy things across?
affects_2.9This issue/PR affects Ansible v2.9bugThis issue/PR relates to a bug.has_prThis issue has an associated PR.moduleThis issue/PR relates to a module.P3Priority 3 - Approved, No Time LimitationverifiedThis issue has been verified/reproduced by maintainer
Summary
When using the
copy
module withremote_src: true
, I'm observing unexpected behavior where the pre-existing files' ownership in the destination folder gets modified by the playbook:Before:
After: (existing leavemebe.txt got it's owner/group changed)
Issue Type
Bug Report
Component Name
ansible.builtin.copy
Ansible Version
Configuration
OS / Environment
Red Hat Enterprise Linux release 8.6 (Ootpa)
Steps to Reproduce
This behavior only happens with using remote_src: true. When running the copy module on the same Ansible host, this behavior does not occur.
Expected Results
I expected the copy module to only modify the file ownership of the copied files (copyme.txt) and not the pre-existing files' ownerships in the destination directory (leavemebe.txt).
Actual Results
We can see that the playbook changed both the copied files (copyme.txt) and existing files (leavemebe.txt)'s ownership to root:root in the destination directory.
Code of Conduct
The text was updated successfully, but these errors were encountered: