diff options
author | James Cammarata <jimi@sngx.net> | 2014-05-27 16:04:02 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2014-06-09 14:10:40 -0500 |
commit | ce80c0b8afc058f63e65d6f2b1c4a0b48bf8500a (patch) | |
tree | 1c60ac979f0e0a5f4456718c765a951dc7cf69d2 | |
parent | b50a64b0a17b9153baced2b6db0b036bc3ccea99 (diff) | |
download | ansible-ce80c0b8afc058f63e65d6f2b1c4a0b48bf8500a.tar.gz |
Support checking for su user to atomic_move
Fixes #7553
-rw-r--r-- | lib/ansible/module_utils/basic.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index e06b5cf568..bd43ede82c 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -1020,6 +1020,7 @@ class AnsibleModule(object): context = self.selinux_default_context(dest) creating = not os.path.exists(dest) + switched_user = os.getlogin() != pwd.getpwuid(os.getuid())[0] try: # Optimistically try a rename, solves some corner cases and can avoid useless work, throws exception if not atomic. @@ -1035,7 +1036,7 @@ class AnsibleModule(object): prefix=".ansible_tmp", dir=dest_dir, suffix=dest_file) try: # leaves tmp file behind when sudo and not root - if os.getenv("SUDO_USER") and os.getuid() != 0: + if switched_user and os.getuid() != 0: # cleanup will happen by 'rm' of tempdir # copy2 will preserve some metadata shutil.copy2(src, tmp_dest.name) @@ -1058,7 +1059,7 @@ class AnsibleModule(object): umask = os.umask(0) os.umask(umask) os.chmod(dest, 0666 ^ umask) - if os.getenv("SUDO_USER"): + if switched_user: os.chown(dest, os.getuid(), os.getgid()) if self.selinux_enabled(): |