add ssh_import_id cloud-config module

This commit is contained in:
Scott Moser 2010-06-18 14:24:48 -04:00
parent ec89b9b976
commit 0adf05faad
3 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import cloudinit.util as util
import subprocess
import traceback
def handle(name,cfg,cloud,log,args):
if len(args) != 0:
user = args[0]
ids = [ ]
if len(args) > 1:
ids = args[1:]
else:
user = util.get_cfg_option_str(cfg,"user","ubuntu")
ids = util.get_cfg_option_list_or_str(cfg,"ssh_import_id",[])
log.warn("here, args = %s. user = %s ids = %s" % ( args, user, ids ))
if len(ids) == 0: return
cmd = [ "sudo", "-Hu", user, "ssh-import-lp-id" ] + ids
log.debug("importing ssh ids. cmd = %s" % cmd)
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError as e:
log.debug(traceback.format_exc(e))
raise Exception("Cmd returned %s: %s" % ( e.returncode, cmd))
except OSError as e:
log.debug(traceback.format_exc(e))
raise Exception("Cmd failed to execute: %s" % ( cmd ))

View File

@ -39,6 +39,7 @@ disable_root: 1
cloud_config_modules:
- mounts
- ssh-import-id
- ssh
- apt-update-upgrade
- puppet

View File

@ -205,3 +205,10 @@ cloud_config_modules:
- config-puppet
- config-ssh
- disable-ec2-metadata
# ssh_import_id: [ user1, user2 ]
# ssh_import_id will feed the list in that variable to
# ssh-import-lp-id, so that public keys stored in launchpad
# can easily be imported into the configured user
# This can be a single string ('smoser') or a list ([smoser, kirkland])
ssh_import_id: [smoser]