summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Li <orpheus+devel@gmail.com>2015-08-21 17:55:28 +0100
committerSimon Li <orpheus+devel@gmail.com>2015-08-21 17:55:28 +0100
commit428550e179f7a57202b452ba3e530b3c791f695e (patch)
tree55fee517e0c8b898bc912aa416932bfdc20fa0d1
parent2af3f34d5848c69d82bf6f18e1e279fd44e6f5ee (diff)
downloadansible-modules-core-428550e179f7a57202b452ba3e530b3c791f695e.tar.gz
Don't fail in check_mode if user exists
PR #1651 fixed issue #1515 but the requirement for path to be defined is unecessarily strict. If the user has previously been created a path isn't necessary.
-rw-r--r--system/authorized_key.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/system/authorized_key.py b/system/authorized_key.py
index f9f773d8..376cf4c6 100644
--- a/system/authorized_key.py
+++ b/system/authorized_key.py
@@ -169,16 +169,15 @@ def keyfile(module, user, write=False, path=None, manage_dir=True):
:return: full path string to authorized_keys for user
"""
- if module.check_mode:
- if path is None:
- module.fail_json(msg="You must provide full path to key file in check mode")
- else:
- keysfile = path
- return keysfile
+ if module.check_mode and path is not None:
+ keysfile = path
+ return keysfile
try:
user_entry = pwd.getpwnam(user)
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)))
if path is None:
homedir = user_entry.pw_dir