From 4d732d74db4d94af338764fb960e2a1cd2b3e94a Mon Sep 17 00:00:00 2001 From: Steve Noyes Date: Fri, 15 Jun 2018 14:46:08 -0400 Subject: [PATCH] Add ssh key generation to setup script - The cli needs the public key in /etc/kolla/kolla-cli. If the key has not yet been generated, generate it first. - Have the script fail and not continue if it hits any command error. - Make the inventory touch happen all the time so the script will fail if you do not have sufficient privs to run the script. Change-Id: I4dc1e1ce8d1839e7550479799fb00e2613d979df --- cli_setup.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cli_setup.py b/cli_setup.py index 076663c..275b2f1 100755 --- a/cli_setup.py +++ b/cli_setup.py @@ -38,10 +38,11 @@ def setup_ansible_etc(): make_cli_etc_dir_cmd = ('mkdir -p %s' % cli_etc_dir) _command_exec(make_cli_etc_dir_cmd) + # Create the inventory file (if it doesn't already exist). + # (The script will exit here if the user doesn't have sufficient privs.) inventory_file_path = os.path.join(cli_etc_dir, 'inventory.json') - if not os.path.exists(inventory_file_path): - touch_inventory_file_cmd = ('touch %s' % inventory_file_path) - _command_exec(touch_inventory_file_cmd) + touch_inventory_file_cmd = ('touch %s' % inventory_file_path) + _command_exec(touch_inventory_file_cmd) # copy over all kolla ansible etc files kolla_ansible_etc_source = os.path.join(kolla_ansible_source_base, @@ -50,6 +51,18 @@ def setup_ansible_etc(): kolla_ansible_etc_target)) _command_exec(copy_kolla_etc_files_cmd) + # add ssh keys for cli + key_path = os.path.join(os.getenv('HOME'), '.ssh', 'id_rsa') + if not os.path.exists(key_path): + # generate new ssh keys + keygen_cmd = 'ssh-keygen -t rsa -N \'\' -f %s' % key_path + _command_exec(keygen_cmd) + # copy the public key to where kolla-cli expects it + pub_key_path = os.path.join(os.getenv('HOME'), '.ssh', 'id_rsa.pub') + cli_etc_path = os.path.join(kolla_ansible_etc_target, kolla_cli) + copy_cmd = 'cp -p %s %s/' % (pub_key_path, cli_etc_path) + _command_exec(copy_cmd) + def setup_ansible_home(): # make cli home ansible directory @@ -106,6 +119,7 @@ def _command_exec(command): error, _ = utils.run_cmd(command) if error: print('error - %s' % error) + sys.exit(1) def main():