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.