From b9d39a834af1c6c30122f503aba695e49f4fecca Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 18 Jun 2010 14:24:48 -0400 Subject: add ssh_import_id cloud-config module --- cloudinit/CloudConfig/cc_ssh_import_id.py | 29 +++++++++++++++++++++++++++++ cloudinit/__init__.py | 1 + doc/examples/cloud-config.txt | 7 +++++++ 3 files changed, 37 insertions(+) create mode 100644 cloudinit/CloudConfig/cc_ssh_import_id.py diff --git a/cloudinit/CloudConfig/cc_ssh_import_id.py b/cloudinit/CloudConfig/cc_ssh_import_id.py new file mode 100644 index 00000000..e5d39ae9 --- /dev/null +++ b/cloudinit/CloudConfig/cc_ssh_import_id.py @@ -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 )) diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index 624b8ee8..50da30c0 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -39,6 +39,7 @@ disable_root: 1 cloud_config_modules: - mounts + - ssh-import-id - ssh - apt-update-upgrade - puppet diff --git a/doc/examples/cloud-config.txt b/doc/examples/cloud-config.txt index 144820a9..4cb435f6 100644 --- a/doc/examples/cloud-config.txt +++ b/doc/examples/cloud-config.txt @@ -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] -- cgit v1.2.3