|
|
|
@ -185,7 +185,8 @@ def keyfile(module, user, write=False, path=None, manage_dir=True):
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
user_entry = pwd.getpwnam(user)
|
|
|
|
|
except KeyError, e:
|
|
|
|
|
except KeyError:
|
|
|
|
|
e = get_exception()
|
|
|
|
|
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)))
|
|
|
|
@ -205,11 +206,11 @@ def keyfile(module, user, write=False, path=None, manage_dir=True):
|
|
|
|
|
|
|
|
|
|
if manage_dir:
|
|
|
|
|
if not os.path.exists(sshdir):
|
|
|
|
|
os.mkdir(sshdir, 0700)
|
|
|
|
|
os.mkdir(sshdir, int('0700', 8))
|
|
|
|
|
if module.selinux_enabled():
|
|
|
|
|
module.set_default_selinux_context(sshdir, False)
|
|
|
|
|
os.chown(sshdir, uid, gid)
|
|
|
|
|
os.chmod(sshdir, 0700)
|
|
|
|
|
os.chmod(sshdir, int('0700', 8))
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(keysfile):
|
|
|
|
|
basedir = os.path.dirname(keysfile)
|
|
|
|
@ -224,7 +225,7 @@ def keyfile(module, user, write=False, path=None, manage_dir=True):
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
os.chown(keysfile, uid, gid)
|
|
|
|
|
os.chmod(keysfile, 0600)
|
|
|
|
|
os.chmod(keysfile, int('0600', 8))
|
|
|
|
|
except OSError:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
@ -349,7 +350,8 @@ def writekeys(module, filename, keys):
|
|
|
|
|
except:
|
|
|
|
|
key_line = key
|
|
|
|
|
f.writelines(key_line)
|
|
|
|
|
except IOError, e:
|
|
|
|
|
except IOError:
|
|
|
|
|
e = get_exception()
|
|
|
|
|
module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, str(e)))
|
|
|
|
|
f.close()
|
|
|
|
|
module.atomic_move(tmp_path, filename)
|
|
|
|
|