1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Set proper file permisions when a file is created with atomic_move

Fixes #7196
This commit is contained in:
Jiri Barton 2014-04-29 08:40:08 -05:00 committed by James Cammarata
parent 9a6998aa17
commit 9da06274a8

View file

@ -1020,8 +1020,14 @@ class AnsibleModule(object):
self.cleanup(tmp_dest.name)
self.fail_json(msg='Could not replace file: %s to %s: %s' % (src, dest, e))
if creating and os.getenv("SUDO_USER"):
os.chown(dest, os.getuid(), os.getgid())
if creating:
# make sure the file has the correct permissions
# based on the current value of umask
umask = os.umask(0)
os.umask(umask)
os.chmod(dest, 0666 ^ umask)
if os.getenv("SUDO_USER"):
os.chown(dest, os.getuid(), os.getgid())
if self.selinux_enabled():
# rename might not preserve context