From 25ea14bdcc3786f92746dc123e844aecee37cbeb Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Tue, 17 Jun 2014 18:30:50 +0200 Subject: [PATCH] Download Vagrant insecure private key if necessary Rather than expecting the user to download the Vagrant insecure private key and put it into the appropriate directory, the script downloads the key if it's not already there. This patch also adds a README.rst. It explains the purpose of the directory which may also be used to cache the matching public key (used inside the VMs). Partial-Bug: 1312764 Implements: blueprint openstack-training-labs Change-Id: If0ee801f6f581230304ad5899b381680bce9154e --- labs/lib/osbash/functions.host | 19 +++++++++++++++++++ labs/lib/vagrant-ssh-keys/README.rst | 4 ++++ 2 files changed, 23 insertions(+) create mode 100644 labs/lib/vagrant-ssh-keys/README.rst diff --git a/labs/lib/osbash/functions.host b/labs/lib/osbash/functions.host index 3a82a99c..649a9fa3 100644 --- a/labs/lib/osbash/functions.host +++ b/labs/lib/osbash/functions.host @@ -40,6 +40,19 @@ function get_base_disk_path { #------------------------------------------------------------------------------- # ssh #------------------------------------------------------------------------------- + +# Download Vagrant insecure private key if necessary +function check_vagrant_private_key { + local KEY_NAME="vagrant" + local KEY_URL=https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/$KEY_NAME + local VAGRANT_KEY_DIR=$LIB_DIR/vagrant-ssh-keys + + if [ ! -f "$VAGRANT_KEY_DIR/$KEY_NAME" ]; then + download "$KEY_URL" "$VAGRANT_KEY_DIR" $KEY_NAME + chmod 400 "$VAGRANT_KEY_DIR/$KEY_NAME" + fi +} + function strip_top_dir { local FULL_PATH=$1 echo "${FULL_PATH/$TOP_DIR\//}" @@ -49,6 +62,9 @@ function strip_top_dir { function vm_scp_to_vm { local SSH_PORT=$1 shift + + check_vagrant_private_key + while (($#)); do local SRC_PATH=$1 shift @@ -68,6 +84,9 @@ function vm_scp_to_vm { function vm_ssh { local SSH_PORT=$1 shift + + check_vagrant_private_key + ssh -q \ -i "$LIB_DIR/vagrant-ssh-keys/vagrant" \ -o "UserKnownHostsFile /dev/null" \ diff --git a/labs/lib/vagrant-ssh-keys/README.rst b/labs/lib/vagrant-ssh-keys/README.rst new file mode 100644 index 00000000..2014f657 --- /dev/null +++ b/labs/lib/vagrant-ssh-keys/README.rst @@ -0,0 +1,4 @@ +This directory may contain cached copies of the insecure Vagrant keys from +https://github.com/mitchellh/vagrant/tree/master/keys. + +They allow ssh access to Vagrant VMs or (if enabled) osbash VMs.