diff --git a/bin/userdata.sh b/bin/userdata.sh.template similarity index 87% rename from bin/userdata.sh rename to bin/userdata.sh.template index d1fd299..168fc1c 100644 --- a/bin/userdata.sh +++ b/bin/userdata.sh.template @@ -16,5 +16,10 @@ sudo sed -i -e 's/sleep\ 20/sleep\ 1/g' -e 's/sleep\ 40/sleep\ 1/g' \ -e 's/sleep\ 59/sleep\ 1/g' /etc/init/failsafe.conf sudo sed -i 's/long=120/long=20/g' /etc/init/cloud-init-nonet.conf +# template_str, two args are (user, ssh_keycontent) +cat >> /home/%s/.ssh/authorized_keys < 5: @@ -109,17 +110,12 @@ class Orchestrator(object): self.dst_dir = os.path.abspath(dst_dir) with open(os.path.join(self.src_dir, userdata), 'r') as fin: self.userdata = fin.read() - inject_script = "" - if ssh_keyfile: - # Inject the extra ssh public key - with open(ssh_keyfile, "r") as keyfile: - key_content = keyfile.read() - inject_script = """ -cat >> /home/%s/.ssh/authorized_keys < EOF -%s -EOF -""" % (user, key_content) - self.userdata += inject_script + # Inject the extra ssh public key if any + ssh_keycontent = '' + if ssh_keyfile: + with open(ssh_keyfile, 'r') as fin: + ssh_keycontent = fin.read() + self.userdata = self.userdata % (user, ssh_keycontent) self.timeout = timeout self.poll_interval = poll_interval # scripts to run on chefserver, execute one by one (sequence matters) @@ -502,12 +498,14 @@ def main(): """ program starting point """ + # default argument values shell = False atomic = False cleanup = False chef_repo = "git://github.com/maoy/inception-chef-repo.git" chef_repo_branch = "master" parallel = False + ssh_keyfile = None try: optlist, _ = getopt.getopt(sys.argv[1:], 'p:n:', ["shell", "atomic", "cleanup", "parallel", @@ -528,14 +526,14 @@ def main(): chef_repo_branch = optdict["--chef-repo-branch"] if "--parallel" in optdict: parallel = True - ssh_keyfile = optdict.get("--ssh-keyfile", None) + if "--ssh-keyfile" in optdict: + ssh_keyfile = optdict["--ssh-keyfile"] except Exception: print traceback.format_exc() usage() sys.exit(1) orchestrator = Orchestrator(prefix, num_workers, chef_repo, - chef_repo_branch, parallel, - ssh_keyfile=ssh_keyfile) + chef_repo_branch, parallel, ssh_keyfile) if shell: # give me a ipython shell IPython.embed()