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

Accept numeric user and group parameters

This commit is contained in:
Aaron Brady 2013-04-23 14:05:01 +01:00
parent 1f96925159
commit d2e457f81f

View file

@ -369,9 +369,12 @@ class AnsibleModule(object):
user, group = self.user_and_group(path) user, group = self.user_and_group(path)
if owner != user: if owner != user:
try: try:
uid = pwd.getpwnam(owner).pw_uid uid = int(owner)
except KeyError: except ValueError:
self.fail_json(path=path, msg='chown failed: failed to look up user %s' % owner) try:
uid = pwd.getpwnam(owner).pw_uid
except KeyError:
self.fail_json(path=path, msg='chown failed: failed to look up user %s' % owner)
if self.check_mode: if self.check_mode:
return True return True
try: try:
@ -390,9 +393,12 @@ class AnsibleModule(object):
if self.check_mode: if self.check_mode:
return True return True
try: try:
gid = grp.getgrnam(group).gr_gid gid = int(group)
except KeyError: except ValueError:
self.fail_json(path=path, msg='chgrp failed: failed to look up group %s' % group) try:
gid = grp.getgrnam(group).gr_gid
except KeyError:
self.fail_json(path=path, msg='chgrp failed: failed to look up group %s' % group)
try: try:
os.chown(path, -1, gid) os.chown(path, -1, gid)
except OSError: except OSError: