diff --git a/azure/create-inject.sh b/azure/create-inject.sh new file mode 100644 index 0000000..a6eef34 --- /dev/null +++ b/azure/create-inject.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +set -e + +group="injection" +storage_account="${group}" + +location="westeurope" + +vm_name="$1" + +vm_size="Standard_DS5_v2" +vm_subnet="/subscriptions/49b7f681-8efc-4689-8524-870fc0c1db09/resourceGroups/swh-resource/providers/Microsoft.Network/virtualNetworks/swh-vnet/subnets/default" +vm_diagnostics="http://swhresourcediag966.blob.core.windows.net/" + +vm_user="injection" +vm_sshkey="~/.ssh/id_rsa.inria.pub" + +vm_ndisks=11 + +if ! azure group show "$group" >/dev/null; then + azure group create "$group" "$location" +fi + +if ! azure storage account show -g "$group" "$storage_account"; then + azure storage account create -g "$group" -l "$location" "$storage_account" +fi + +azure vm create \ + -g "${group}" \ + -n "${vm_name}" \ + -l "${location}" \ + -y Linux -Q credativ:Debian:8:latest \ + -S "${vm_subnet}" \ + -f "${vm_name}-if" \ + -i "${vm_name}-public" --public-ip-domain-name "swh${vm_name}" --public-ip-idletimeout 30 \ + -u "${vm_user}" -M "${vm_sshkey}" \ + -o "${storage_account}" \ + -z "${vm_size}" \ + --boot-diagnostics-storage-uri "${vm_diagnostics}" + +for disk in $(seq 1 "${vm_ndisks}"); do + azure vm disk attach-new \ + -g "${group}" \ + -n "${vm_name}" \ + -z 1023 \ + -d "${vm_name}-data${disk}.vhd" \ + -l "${disk}" \ + -o "${storage_account}" +done + +vm_hostname="swh${vm_name}.${location}.cloudapp.azure.com" +scp -i "${vm_sshkey}" provision-inject.sh "${vm_user}@${vm_hostname}:" +ssh -i "${vm_sshkey}" "${vm_user}@${vm_hostname}" sudo bash provision-inject.sh diff --git a/azure/create-vm.sh b/azure/create-vm.sh new file mode 100755 index 0000000..edc4e9a --- /dev/null +++ b/azure/create-vm.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +worker=${1-worker01} +zone=westeurope +resource_prefix=euwest +resource_group="${resource_prefix}-workers" +image=credativ:Debian:9:latest +# pub_key=~/.ssh/id-rsa-swhworker.pub +pub_key=~/.ssh/id_rsa.inria.pub + +# "default" subnet in the "swh-vnet" virtual network of the "swh-resource" resource group +subnet=/subscriptions/49b7f681-8efc-4689-8524-870fc0c1db09/resourceGroups/swh-resource/providers/Microsoft.Network/virtualNetworks/swh-vnet/subnets/default + +# Change for virtual machine size. Standard_DS = SSD; Standard_S = Standard disk +# size=Standard_DS11_v2 +size=Standard_DS2_v2 + +# SSD +disk_group="${resource_prefix}workersdisks" +# Standard +# disk_group="${resource_prefix}stddisks" + +diagnostics_resource=swhresourcediag966 + +azure vm create \ + -g "${resource_group}" \ + -n "${worker}-${resource_prefix}" \ + -l "${zone}" \ + -y Linux -Q "${image}" \ + -S "${subnet}" -f "${worker}-${resource_prefix}-if" \ + -u testadmin -M "${pub_key}" \ + -o "${disk_group}" \ + -z "${size}" \ + --boot-diagnostics-storage-uri "http://${diagnostics_resource}.blob.core.windows.net/" diff --git a/azure/provision-inject.sh b/azure/provision-inject.sh new file mode 100644 index 0000000..e7c3f70 --- /dev/null +++ b/azure/provision-inject.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +set -e + +cat >> /home/injection/.ssh/authorized_keys < /etc/apt/sources.list.d/softwareheritage.list < /etc/apt/preferences.d/objstorage_cloud.pref < /etc/mdadm/mdadm.conf +update-initramfs -k all -u diff --git a/azure/provision-vm-azure-step1.sh b/azure/provision-vm-azure-step1.sh new file mode 100755 index 0000000..80692f0 --- /dev/null +++ b/azure/provision-vm-azure-step1.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# as a first step, connect to the newly vm created +# $ ssh -i ~/.ssh/id_rsa_inria testadmin@ +# then as root +# $ sudo su - +# first add a generated pass +# $ passwd + +# Then permit root connection with ssh +sed -e 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' -i /etc/ssh/sshd_config +sed -e 's/PasswordAuthentication no/PasswordAuthentication yes/g' -i /etc/ssh/sshd_config +systemctl restart sshd.service + +# disconnect from the current connection +# $ logout +# reconnect as root +# scp the provision-vm.sh script to the root user of the vm +# $ scp provision-vm.sh root@ +# connect to the vm +# $ ssh root@ +# $ chmod +x provision-vm.sh +# trigger the script provision-vm.sh +# $ ./provision-vm.sh diff --git a/azure/provision-vm.sh b/azure/provision-vm.sh new file mode 100755 index 0000000..ff1509d --- /dev/null +++ b/azure/provision-vm.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +set -ex + +cd / + +ORIG_HOSTNAME="$(hostname)" +HOSTNAME=${ORIG_HOSTNAME/-*/}.euwest.azure + +IP=$(ip a | grep 192 | awk '{print $2}' | awk -F/ '{print $1}') + +apt-get update +apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade + +echo $HOSTNAME > /etc/hostname +hostnamectl set-hostname $HOSTNAME +cat >> /etc/hosts << EOF +$IP $HOSTNAME.internal.softwareheritage.org $HOSTNAME + +192.168.100.100 db +192.168.100.101 uffizi +192.168.100.31 moma +EOF + +mkdir -p /etc/resolvconf/resolv.conf.d +echo search internal.softwareheritage.org > /etc/resolvconf/resolv.conf.d/tail +apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install resolvconf nfs-common + +apt-get update + +apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade +apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install augeas-tools puppet + + +# FIXME: Is this useful? +augtool << "EOF" +set /files/etc/puppet/puppet.conf/main/pluginsync true +set /files/etc/puppet/puppet.conf/main/server pergamon.internal.softwareheritage.org +save +EOF + +mkdir -p /etc/facter/facts.d +echo location=azure_euwest > /etc/facter/facts.d/location.txt + +service puppet stop +systemctl disable puppet.service +puppet agent --enable + +augtool << "EOF" +set /files/etc/puppet/puppet.conf/agent/server pergamon.internal.softwareheritage.org +set /files/etc/puppet/puppet.conf/agent/report true +set /files/etc/puppet/puppet.conf/agent/pluginsync true +save +EOF + +rm -rf /root/.ssh + +deluser testadmin +rm -rf /home/testadmin + +puppet agent --test || true + +reboot