Teach the user module to understand check mode.

reviewable/pr18780/r1
Michael DeHaan 12 years ago
parent 1900cc68a7
commit 69784f0215

12
user

@ -351,6 +351,8 @@ class User(object):
# skip if no changes to be made # skip if no changes to be made
if len(cmd) == 1: if len(cmd) == 1:
return (None, '', '') return (None, '', '')
elif self.check_mode:
return (True, '', '')
cmd.append(self.name) cmd.append(self.name)
return self.execute_command(cmd) return self.execute_command(cmd)
@ -947,6 +949,8 @@ class AIX(User):
# skip if no changes to be made # skip if no changes to be made
if len(cmd) == 1: if len(cmd) == 1:
(rc, out, err) = (None, '', '') (rc, out, err) = (None, '', '')
elif self.check_mode:
return (True, '', '')
else: else:
cmd.append(self.name) cmd.append(self.name)
(rc, out, err) = self.execute_command(cmd) (rc, out, err) = self.execute_command(cmd)
@ -1002,7 +1006,8 @@ def main():
ssh_key_file=dict(default=None), ssh_key_file=dict(default=None),
ssh_key_comment=dict(default=ssh_defaults['comment']), ssh_key_comment=dict(default=ssh_defaults['comment']),
ssh_key_passphrase=dict(default=None) ssh_key_passphrase=dict(default=None)
) ),
supports_check_mode=True
) )
user = User(module) user = User(module)
@ -1021,6 +1026,8 @@ def main():
result['state'] = user.state result['state'] = user.state
if user.state == 'absent': if user.state == 'absent':
if user.user_exists(): if user.user_exists():
if module.check_mode:
module.exit_json(changed=True)
(rc, out, err) = user.remove_user() (rc, out, err) = user.remove_user()
if rc != 0: if rc != 0:
module.fail_json(name=user.name, msg=err, rc=rc) module.fail_json(name=user.name, msg=err, rc=rc)
@ -1028,10 +1035,13 @@ def main():
result['remove'] = user.remove result['remove'] = user.remove
elif user.state == 'present': elif user.state == 'present':
if not user.user_exists(): if not user.user_exists():
if module.check_mode:
module.exit_json(changed=True)
(rc, out, err) = user.create_user() (rc, out, err) = user.create_user()
result['system'] = user.system result['system'] = user.system
result['createhome'] = user.createhome result['createhome'] = user.createhome
else: else:
# modify user (note: this function is check mode aware)
(rc, out, err) = user.modify_user() (rc, out, err) = user.modify_user()
result['append'] = user.append result['append'] = user.append
if rc is not None and rc != 0: if rc is not None and rc != 0:

Loading…
Cancel
Save