mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #838 from sfromm/issue825
Update file module to not recurse when setting ownership
This commit is contained in:
commit
36527ca9d5
1 changed files with 14 additions and 4 deletions
18
library/file
18
library/file
|
@ -161,8 +161,13 @@ def set_owner_if_different(path, owner, changed):
|
||||||
return changed
|
return changed
|
||||||
user, group = user_and_group(path)
|
user, group = user_and_group(path)
|
||||||
if owner != user:
|
if owner != user:
|
||||||
rc = os.system("/bin/chown -R %s %s 2>/dev/null" % (owner, path))
|
try:
|
||||||
if rc != 0:
|
uid = pwd.getpwnam(owner).pw_uid
|
||||||
|
except KeyError:
|
||||||
|
module_fail_json(path=path, msg='chown failed: failed to look up user %s' % owner)
|
||||||
|
try:
|
||||||
|
os.chown(path, uid, -1)
|
||||||
|
except OSError:
|
||||||
module_fail_json(path=path, msg='chown failed')
|
module_fail_json(path=path, msg='chown failed')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -173,8 +178,13 @@ def set_group_if_different(path, group, changed):
|
||||||
return changed
|
return changed
|
||||||
old_user, old_group = user_and_group(path)
|
old_user, old_group = user_and_group(path)
|
||||||
if old_group != group:
|
if old_group != group:
|
||||||
rc = os.system("/bin/chgrp -R %s %s" % (group, path))
|
try:
|
||||||
if rc != 0:
|
gid = grp.getgrnam(group).gr_gid
|
||||||
|
except KeyError:
|
||||||
|
module_fail_json(path=path, msg='chgrp failed: failed to look up group %s' % group)
|
||||||
|
try:
|
||||||
|
os.chown(path, -1, gid)
|
||||||
|
except OSError:
|
||||||
module_fail_json(path=path, msg='chgrp failed')
|
module_fail_json(path=path, msg='chgrp failed')
|
||||||
return True
|
return True
|
||||||
return changed
|
return changed
|
||||||
|
|
Loading…
Reference in a new issue