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

copy: do not chmod if mode in not set #40220

Closed
user318 opened this issue May 16, 2018 · 15 comments
Closed

copy: do not chmod if mode in not set #40220

user318 opened this issue May 16, 2018 · 15 comments
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. files Files category has_pr This issue has an associated PR. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@user318
Copy link

user318 commented May 16, 2018

ISSUE TYPE
  • Bug Report
COMPONENT NAME

copy module

ANSIBLE VERSION
ansible 2.5.2
  config file = /home/user/.ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/soft/test/lib/python3.6/site-packages/ansible
  executable location = /home/user/soft/test/bin/ansible
  python version = 3.6.1 (default, Jun  2 2017, 15:55:17) [GCC 4.8.4]
CONFIGURATION

N/A

OS / ENVIRONMENT

from Ubuntu Linux
manage Arista switch with Fedora-based OS
or
manage another Ubuntu Linux

SUMMARY

When using "copy" module with destination on a file system not supporting chmod(), I'm getting an exception.
vfat not always returns an error on chmod() call. If the filesystem is owned by the same user, it does not actually change permissions, but returns no error. If another user is able to write to this filesystem - for him chmod returns an error.
chmod() should not be called when mode is not specified or errors from it should be ignored.

STEPS TO REPRODUCE
ansible arista -u ansible -m copy -a "src=test.txt dest=/mnt/flash/test.txt" -vvv

Example of operations on vfat mount from user not owning the fs, but with write access:

user:/mnt/tmp$ ls -lha
total 25K
drwxrwx--- 2 nobody user 16K May 16 09:59 .
drwxr-xr-x 3 root   root   3 Apr 15  2017 ..
-rwxrwx--- 1 nobody user   0 May 16 09:53 1.txt
user:/mnt/tmp$ touch test.txt
user:/mnt/tmp$ ls -lha
total 25K
drwxrwx--- 2 nobody user 16K May 16 10:03 .
drwxr-xr-x 3 root   root   3 Apr 15  2017 ..
-rwxrwx--- 1 nobody user   0 May 16 09:53 1.txt
-rwxrwx--- 1 nobody user   0 May 16 10:03 test.txt
user:/mnt/tmp$ chmod 755 test.txt 
chmod: changing permissions of 'test.txt': Operation not permitted
user:/mnt/tmp$ 

User can create file, but chmod returns an error. The owner (nobody) have no error on chmod;

nobody:/mnt/tmp$ ls -lha
total 25K
drwxrwx--- 2 nobody user 16K May 16 10:03 .
drwxr-xr-x 3 root   root   3 Apr 15  2017 ..
-rwxrwx--- 1 nobody user   0 May 16 09:53 1.txt
-rwxrwx--- 1 nobody user   0 May 16 10:03 test.txt
nobody:/mnt/tmp$ chmod 755 test.txt
nobody:/mnt/tmp$ ls -lha
total 25K
drwxrwx--- 2 nobody user 16K May 16 10:03 .
drwxr-xr-x 3 root   root   3 Apr 15  2017 ..
-rwxrwx--- 1 nobody user   0 May 16 09:53 1.txt
-rwxrwx--- 1 nobody user   0 May 16 10:03 test.txt
nobody:/mnt/tmp$ 
EXPECTED RESULTS

No errors, file copied to managed host.

ACTUAL RESULTS
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_WKlj_b/ansible_modlib.zip/ansible/module_utils/basic.py", line 2536, in atomic_move
    shutil.copy2(b_src, b_tmp_dest_name)
  File "/usr/lib/python2.7/shutil.py", line 128, in copy2
    copystat(src, dst)
  File "/usr/lib/python2.7/shutil.py", line 99, in copystat
    os.chmod(dst, mode)
OSError: [Errno 1] Operation not permitted: '/mnt/flash/.ansible_tmpAsS9sftest.txt'

aristalab | FAILED! => {
    "changed": false,
    "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "diff": [],
    "invocation": {
        "module_args": {
            "attributes": null,
            "backup": false,
            "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
            "content": null,
            "delimiter": null,
            "dest": "/mnt/flash/test.txt",
            "directory_mode": null,
            "follow": false,
            "force": true,
            "group": null,
            "local_follow": null,
            "mode": null,
            "original_basename": "test.txt",
            "owner": null,
            "regexp": null,
            "remote_src": null,
            "selevel": null,
            "serole": null,
            "setype": null,
            "seuser": null,
            "src": "/home/ansible/.ansible/tmp/ansible-tmp-1526452633.1935987-117985603557511/source",
            "unsafe_writes": null,
            "validate": null
        }
    },
    "msg": "Failed to replace file: /home/ansible/.ansible/tmp/ansible-tmp-1526452633.1935987-117985603557511/source to /mnt/flash/test.txt: [Errno 1] Operation not permitted: '/mnt/flash/.ansible_tmpAsS9sftest.txt'"
}
@ansibot
Copy link
Contributor

ansibot commented May 16, 2018

Files identified in the description:

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

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels May 16, 2018
@jborean93 jborean93 removed needs_triage Needs a first human triage before being processed. python3 labels May 17, 2018
@ansibot ansibot added the traceback This issue/PR includes a traceback. label May 25, 2018
@cu
Copy link

cu commented Aug 10, 2018

Probable dupe of #7372 and #19731

@user318
Copy link
Author

user318 commented Aug 11, 2018

@cu In #19731 it was fixed only for remote_src=True and I was asked to file a separate bug.

@user318
Copy link
Author

user318 commented Aug 11, 2018

And #7372 is about chown(). This about chmod(). And patch there compares uid/gid to figure out wether to do chown() or not. But I want to be able to have an option to skip chown/chmod completely. So one can use filesystems which do not support those operations.

@ansibot
Copy link
Contributor

ansibot commented Sep 12, 2018

cc @ptux
click here for bot help

@ansibot ansibot added the files Files category label Mar 5, 2019
@user318
Copy link
Author

user318 commented Jun 23, 2019

This changes works for me. Not sure though if I access mode parameter correctly.

ansible-modeignore.patch.txt

@ansibot ansibot added the has_pr This issue has an associated PR. label Jul 25, 2019
@ansibot
Copy link
Contributor

ansibot commented May 16, 2020

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

@relrod
Copy link
Member

relrod commented Apr 9, 2021

This is expected behavior, copy expects to be copying to a posix-compatible filesystem.

@relrod relrod closed this as completed Apr 9, 2021
@user318
Copy link
Author

user318 commented Apr 9, 2021

So what? Should we throw away any users with non-posix filesystems then? I suggest that ansible has some mode for "copy" when it can be usable for non-posix systems too. Isn't it a reasonable feature?

@bcoca
Copy link
Member

bcoca commented Apr 9, 2021

It is reasonable to a point, for example, have win_copy for windows, for other systems a specific module might be needed per OS, due to the proprietary nature of most of these it is unlikely that the core team will develop them or accept them in core, as collections would be a more appropriate home for them.

@user318
Copy link
Author

user318 commented Apr 9, 2021

Separate module is not a good option, because it will be needed to have a separate module for template too and may be some others, if they depend on copy. Actually it there is not much to do in the copy module itself, but it is something done in supporting functions, that are not flexible enough for such cases. Even if it were a separate module, it would be good, I suppose, to use the same codebase for it.
And I do not actually think that there is need for os-specific modules. For example I do not want win_copy, I need it on Linux running on the Arista switch, which uses FAT filesystem on the flash. This is not my choice, but I have to live with it somehow. And I think that disabling chown/chmod attempts should perform quite well for Windows too. I do not propose to add some OS-specific extra features here, but for the copy module to skip some of its activities.

@bcoca
Copy link
Member

bcoca commented Apr 9, 2021

we HAVE a win_copy module for these reasons, its not just chmod, you would have to disable stating, setfacl, chown, chgrp, selinux context ... and that is just off top of my head.

@user318
Copy link
Author

user318 commented Apr 9, 2021

I have doubt it works for me, because the documentation says:

  • For non-Windows targets, use the copy module instead
  • win_copy runs over WinRM

I have Linux and ssh, do not even know what that WinRM is. :) But I'll try it.

PS. I had problems with the module failing only because of chmod/chown/chgrp - they causes exception. Even if it tries to do something other - it still works without failing.

@bcoca
Copy link
Member

bcoca commented Apr 9, 2021

i'm NOT telling you to use win_copy, i was using it as an example that for non posix systems we would need a dedicated module.

@user318
Copy link
Author

user318 commented Apr 10, 2021

OK, misunderstood it. :)
Anyway, the above error I receive is "Operation not permitted", i.e. permission error. But the module fails on it when I do not want to touch mode/owner. It may even happen on posix-compatible filesystems too. Also there are already several cases in atomic_move to support "non posix-compatible" filesystems. And there are also some checks for situations when access is not allowed (for unsafe_writes).
I do not understand what is bad with adding the option to copy/template/etc. so that they do not touch mode/owner? It is not about posix compatibility. It is not that easy just to make separate xxx_copy module here, because the changes needed are in atomic_move function in basic.py, so those parts need to be almost completely copied just for a couple of simple changes.

@ansible ansible locked and limited conversation to collaborators May 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. files Files category has_pr This issue has an associated PR. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

No branches or pull requests

6 participants