From ad89ab7c5da100d0902da4899b29bf0ad405f2fd Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sun, 17 Feb 2013 17:31:18 -0500 Subject: [PATCH] Add group support to check mode. --- library/group | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/library/group b/library/group index f297cbaea5..03ae1438da 100644 --- a/library/group +++ b/library/group @@ -118,6 +118,8 @@ class Group(object): cmd.append(kwargs[key]) if len(cmd) == 1: return (None, '', '') + if self.module.check_mode: + return (True, '', '') cmd.append(self.name) return self.execute_command(cmd) @@ -201,6 +203,8 @@ class AIX(Group): cmd.append('id='+kwargs[key]) if len(cmd) == 1: return (None, '', '') + if self.module.check_mode: + return (True, '', '') cmd.append(self.name) return self.execute_command(cmd) @@ -213,7 +217,8 @@ def main(): name=dict(required=True), gid=dict(default=None), system=dict(default='no', choices=['yes', 'no']), - ) + ), + supports_check_mode=True ) group = Group(module) @@ -230,13 +235,21 @@ def main(): result = {} result['name'] = group.name result['state'] = group.state + if group.state == 'absent': + if group.group_exists(): + if module.check_mode: + module.exit_json(changed=True) (rc, out, err) = group.group_del() if rc != 0: module.fail_json(name=group.name, msg=err) + elif group.state == 'present': + if not group.group_exists(): + if module.check_mode: + module.exit_json(changed=True) (rc, out, err) = group.group_add(gid=group.gid, system=group.system) else: (rc, out, err) = group.group_mod(gid=group.gid)