#!/bin/bash set -e cd "$(dirname "$0")" # This script is meant to be executed on the management machine. # it reaches out to an SSH endpoint and provisions that machine # to use LXD. DATA_PLANE_MACVLAN_INTERFACE= DISK_TO_USE= # override the remote name. REMOTE_NAME="${1:-}" if [ -z "$REMOTE_NAME" ]; then echo "ERROR: The remote name was not provided. Syntax is: 'ss-remote REMOTE_NAME SSH_HOST_FQDN'" echo " for example: 'ss-remote dev host01.domain.tld" exit 1 fi #shellcheck disable=SC1091 source ../defaults.sh export REMOTE_PATH="$REMOTES_DIR/$REMOTE_NAME" REMOTE_DEFINITION="$REMOTE_PATH/remote_definition" export REMOTE_DEFINITION="$REMOTE_DEFINITION" mkdir -p "$REMOTE_PATH" if [ ! -f "$REMOTE_DEFINITION" ]; then # stub out a remote_definition. cat >"$REMOTE_DEFINITION" <> /etc/sudoers' # if the disk is loop-based, then we assume the / path exists. if [ "$DISK_TO_USE" != loop ]; then # ensure we actually have that disk/partition on the system. if ! ssh "ubuntu@$FQDN" lsblk --paths | grep -q "$DISK_TO_USE"; then echo "ERROR: We could not findthe disk you specified. Please run this command again and supply a different disk." echo "NOTE: You can always specify on the command line by adding the '--disk=/dev/sdd', for example." exit 1 fi fi # The MGMT Plane IP is the IP address that the LXD API binds to, which happens # to be the same as whichever SSH connection you're coming in on. MGMT_PLANE_IP="$(ssh ubuntu@"$FQDN" env | grep SSH_CONNECTION | cut -d " " -f 3)" IP_OF_MGMT_MACHINE="$(ssh ubuntu@"$FQDN" env | grep SSH_CLIENT | cut -d " " -f 1 )" IP_OF_MGMT_MACHINE="${IP_OF_MGMT_MACHINE#*=}" IP_OF_MGMT_MACHINE="$(echo "$IP_OF_MGMT_MACHINE" | cut -d: -f1)" # error out if the remote password is unset. if [ -z "$LXD_REMOTE_PASSWORD" ]; then echo "ERROR: LXD_REMOTE_PASSWORD must be set in your remote_definition." exit 1 fi if ! command -v lxc >/dev/null 2>&1; then if lxc profile list --format csv | grep -q "$BASE_IMAGE_VM_NAME"; then lxc profile delete "$BASE_IMAGE_VM_NAME" sleep 1 fi if lxc network list --format csv | grep -q lxdbr0; then lxc network delete lxdbr0 sleep 1 fi if lxc network list --format csv | grep -q lxdbr1; then lxc network delete lxdbr1 sleep 1 fi fi # install dependencies. ssh -t "ubuntu@$FQDN" 'sudo apt update && sudo apt upgrade -y && sudo apt install htop dnsutils nano -y' if ! ssh "ubuntu@$FQDN" snap list | grep -q lxd; then ssh -t "ubuntu@$FQDN" 'sudo snap install lxd --channel=5.11/stable' sleep 5 fi # install OVN for the project-specific bridge networks ssh -t "ubuntu@$FQDN" "sudo apt-get install -y ovn-host ovn-central" ssh -t "ubuntu@$FQDN" "sudo ovs-vsctl set open_vswitch . external_ids:ovn-remote=unix:/var/run/ovn/ovnsb_db.sock external_ids:ovn-encap-type=geneve external_ids:ovn-encap-ip=127.0.0.1" # if the DATA_PLANE_MACVLAN_INTERFACE is not specified, then we 'll # just attach VMs to the network interface used for for the default route. if [ -z "$DATA_PLANE_MACVLAN_INTERFACE" ]; then DATA_PLANE_MACVLAN_INTERFACE="$(ssh -t ubuntu@"$FQDN" ip route | grep default | cut -d " " -f 5)" fi export DATA_PLANE_MACVLAN_INTERFACE="$DATA_PLANE_MACVLAN_INTERFACE" # run lxd init on the remote server. cat <