From d2e457f81f9432f3f4637af364550ee64528b319 Mon Sep 17 00:00:00 2001 From: Aaron Brady Date: Tue, 23 Apr 2013 14:05:01 +0100 Subject: [PATCH] Accept numeric user and group parameters --- lib/ansible/module_common.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index c5bb9d46b4..a57033910b 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -369,9 +369,12 @@ class AnsibleModule(object): user, group = self.user_and_group(path) if owner != user: try: - uid = pwd.getpwnam(owner).pw_uid - except KeyError: - self.fail_json(path=path, msg='chown failed: failed to look up user %s' % owner) + uid = int(owner) + except ValueError: + 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: return True try: @@ -390,9 +393,12 @@ class AnsibleModule(object): if self.check_mode: return True try: - gid = grp.getgrnam(group).gr_gid - except KeyError: - self.fail_json(path=path, msg='chgrp failed: failed to look up group %s' % group) + gid = int(group) + except ValueError: + 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: os.chown(path, -1, gid) except OSError: