Merge pull request #1952 from manics/authorized_key-check_mode-user_path

Don't fail in authorized_key check_mode if user exists
reviewable/pr18780/r1
Brian Coca 9 years ago
commit 8cc9fdde4a

@ -169,16 +169,15 @@ def keyfile(module, user, write=False, path=None, manage_dir=True):
:return: full path string to authorized_keys for user :return: full path string to authorized_keys for user
""" """
if module.check_mode: if module.check_mode and path is not None:
if path is None:
module.fail_json(msg="You must provide full path to key file in check mode")
else:
keysfile = path keysfile = path
return keysfile return keysfile
try: try:
user_entry = pwd.getpwnam(user) user_entry = pwd.getpwnam(user)
except KeyError, e: except KeyError, e:
if module.check_mode and path is None:
module.fail_json(msg="Either user must exist or you must provide full path to key file in check mode")
module.fail_json(msg="Failed to lookup user %s: %s" % (user, str(e))) module.fail_json(msg="Failed to lookup user %s: %s" % (user, str(e)))
if path is None: if path is None:
homedir = user_entry.pw_dir homedir = user_entry.pw_dir

Loading…
Cancel
Save