aboutsummaryrefslogtreecommitdiffstats
path: root/modules/openssh
diff options
context:
space:
mode:
authorOlivier Blin <dev@blino.org>2017-02-23 01:38:32 +0100
committerOlivier Blin <dev@blino.org>2017-02-23 01:55:45 +0100
commite2577655a15f64af1e74f250c45d3b9d8ae77a6c (patch)
tree2a58c387f1d8e0f1e23afe418307f8b84d2ce3a4 /modules/openssh
parentbbf66681a90a588a288cb0d2a812e7a8ba0706ba (diff)
downloadpuppet-e2577655a15f64af1e74f250c45d3b9d8ae77a6c.tar
puppet-e2577655a15f64af1e74f250c45d3b9d8ae77a6c.tar.gz
puppet-e2577655a15f64af1e74f250c45d3b9d8ae77a6c.tar.bz2
puppet-e2577655a15f64af1e74f250c45d3b9d8ae77a6c.tar.xz
puppet-e2577655a15f64af1e74f250c45d3b9d8ae77a6c.zip
ldap-sshkey2file.py: add dry-run and verbose mode
Diffstat (limited to 'modules/openssh')
-rwxr-xr-xmodules/openssh/templates/ldap-sshkey2file.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/modules/openssh/templates/ldap-sshkey2file.py b/modules/openssh/templates/ldap-sshkey2file.py
index 7c41832d..2d2b2c27 100755
--- a/modules/openssh/templates/ldap-sshkey2file.py
+++ b/modules/openssh/templates/ldap-sshkey2file.py
@@ -43,6 +43,8 @@ parser = argparse.ArgumentParser(
This script is intended to be run from cron as root;
''' % (peopledn, keypathprefix)))
+parser.add_argument('-n', '--dry-run', action='store_true')
+parser.add_argument('-v', '--verbose', action='store_true')
args = parser.parse_args()
def get_bindpw():
@@ -107,6 +109,13 @@ def write_keys(keys, user, uid, gid):
if fromldap == fromfile:
return False
+ if args.dry_run:
+ print "Would write %s" % keyfile
+ return True
+
+ if args.verbose:
+ print "Writing %s" % keyfile
+
if not os.path.isdir("%s/%s" % (keypathprefix,user)):
shutil.copytree('/etc/skel', "%s/%s" % (keypathprefix,user))
os.chown("%s/%s" % (keypathprefix,user), uid, gid)
@@ -152,6 +161,9 @@ try:
except:
pass
+ if args.verbose:
+ print "Found users: " + ", ".join(sorted(map(lambda x: x[1]['uid'][0], res)))
+
for result in res:
dn, entry = result
# skip possible system users
@@ -166,8 +178,12 @@ except Exception, e:
raise
if changed:
+ if args.verbose:
+ print "SSH keys changed"
sys.exit(0)
+if args.verbose:
+ print "No changes in SSH keys"
sys.exit(1)