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
This commit is contained in:
parent
4fc34d1240
commit
4d732d74db
20
cli_setup.py
20
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():
|
||||
|
|
Loading…
Reference in New Issue