]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Merge branch 'split_scripts' into dev
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 19 Mar 2018 15:21:00 +0000 (16:21 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 19 Mar 2018 15:21:00 +0000 (16:21 +0100)
21 files changed:
bin/install_script.sh [new file with mode: 0755]
bin/install_script_ovh_cloud_instance.sh [deleted file]
bin/install_script_ovh_vps_ssd.sh [deleted file]
modules/base_installation/templates/puppet/host_ldap.info.erb
python/buy_ovh_vps_ssd.py [moved from python/buy_vps_server.py with 100% similarity]
python/get_initial_configuration_ovh_cloud_instance.py [moved from python/get_initial_configuration_cloud_instance.py with 52% similarity]
python/get_initial_configuration_ovh_vps_ssd.py [moved from python/get_initial_configuration.py with 100% similarity]
python/list_servers.py
python/ovh_helper.py
python/reboot_ovh_cloud_instance.py [moved from python/reboot_cloud_instance.py with 52% similarity]
python/reboot_ovh_vps_ssd.py [moved from python/reboot_vps_server.py with 100% similarity]
python/reinstall_ovh_cloud_instance.py [moved from python/reinstall_cloud_instance.py with 71% similarity]
python/reinstall_ovh_vps_ssd.py [moved from python/reinstall_vps_server.py with 100% similarity]
scripts/arch_install_script.sh [new file with mode: 0755]
scripts/arch_puppet_configuration_script.sh [new file with mode: 0755]
scripts/ovh_cloud_instance/arch_host_puppet_configuration_script.sh [new file with mode: 0755]
scripts/ovh_cloud_instance/arch_host_script.sh [new file with mode: 0755]
scripts/ovh_vps_ssd/arch_chroot_script.sh [new file with mode: 0755]
scripts/ovh_vps_ssd/arch_host_puppet_configuration_script.sh [new file with mode: 0755]
scripts/ovh_vps_ssd/arch_host_script.sh [new file with mode: 0755]
scripts/send_and_run.tcl [new file with mode: 0755]

diff --git a/bin/install_script.sh b/bin/install_script.sh
new file mode 100755 (executable)
index 0000000..bd7f38b
--- /dev/null
@@ -0,0 +1,155 @@
+#!/bin/bash
+
+usage() {
+cat <<EOF
+$(basename $0) [options]
+  --help,-h               This help
+
+  One of the following options is necessary:
+  --instance-id id        Id of the cloud instance
+  --vps-id id             Id of the vps
+
+  Optional arguments:
+  --password password     Password of the host (only useful in case of no reboot and vps)
+  --reinstall-first       Start with reinstalling the vps
+  --host-user user        Use another user than the default one
+  --no-reboot             Don't reboot
+  --no-reboot-start       Don't reboot to rescue at the beginning
+  --no-reboot-end         Don't reboot to normal at the end
+  --git-branch branch     Use another puppet branch (default: master)
+  --environment env       Environment to use for the install (default: production)
+EOF
+}
+
+set -e
+
+git_branch=master
+environment=production
+host_user=""
+password=""
+T=""
+
+while [ -n "$1" ]; do
+  case "$1" in
+    --instance-id)
+      host_id="$2"
+      if [ -z "$host_user" ]; then
+        host_user="arch"
+      fi
+      if [ -z "$password" ]; then
+        password="x"
+      fi
+      [ -n "$T" ] && usage && exit 1
+      T="ovh_cloud_instance"
+      shift
+      ;;
+    --vps-id)
+      host_id="$2"
+      if [ -z "$host_user" ]; then
+        host_user="root"
+      fi
+      [ -n "$T" ] && usage && exit 1
+      T="ovh_vps_ssd"
+      shift
+      ;;
+    --password)
+      password="$2"
+      shift
+      ;;
+    --reinstall-first)
+      reinstall_first=1
+      ;;
+    --host-user)
+      host_user="$2"
+      shift
+      ;;
+    --no-reboot)
+      no_reboot=1
+      ;;
+    --no-reboot-start)
+      no_reboot_start=1
+      ;;
+    --no-reboot-end)
+      no_reboot_end=1
+      ;;
+    --git-branch)
+      git_branch="$2"
+      shift
+      ;;
+    --environment)
+      environment="$2"
+      shift
+      ;;
+    --help|-h)
+      usage
+      exit 0
+      ;;
+  esac
+
+  shift
+done
+
+if [ -z "$T" -o -z "$host_id" ]; then
+  usage
+  exit 1
+fi
+
+DIRECTORY=$(cd `dirname $0` && pwd)
+PYTHON_DIRECTORY="$DIRECTORY/../python"
+SCRIPTS="$DIRECTORY/../scripts"
+
+if [ -n "$reinstall_first" ]; then
+  echo "Réinstallation du système"
+  python $PYTHON_DIRECTORY/reinstall_$T.py --use-current "$host_id"
+
+  read -p "Appuyer sur une touche quand le serveur est prêt" ready
+fi
+
+if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
+  echo "Patienter le temps du reboot"
+  python $PYTHON_DIRECTORY/reboot_$T.py --rescue "$host_id"
+
+  read -p "Appuyer sur une touche quand l'instance a redémarré" ready
+fi
+
+if [ -z "$password" ]; then
+  stty -echo
+  read -p "Mot de passe reçu par e-mail : " password; echo
+  stty echo
+fi
+
+ARCH_DIR=`mktemp -d`
+ARCH_HOST_SCRIPT="$SCRIPTS/$T/arch_host_script.sh"
+if [ -f "$SCRIPTS/$T/arch_chroot_script.sh" ]; then
+  ARCH_CHROOT_SCRIPT="$SCRIPTS/$T/arch_chroot_script.sh"
+else
+  ARCH_CHROOT_SCRIPT=""
+fi
+ARCH_INSTALL_SCRIPT="$SCRIPTS/arch_install_script.sh"
+ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/$T/arch_host_puppet_configuration_script.sh"
+ARCH_PUPPET_CONFIGURATION_SCRIPT="$SCRIPTS/arch_puppet_configuration_script.sh"
+ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
+
+trap "rm -rf $ARCH_DIR" EXIT
+
+#### Base installation stage
+python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
+host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_$T.py $host_id | jq -r '.ips.v4.ipAddress')
+
+dest="$host_user@$host_address"
+files="$ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_INSTALL_SCRIPT"
+
+$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
+
+### Role specific stage
+read -p "Press key when LDAP is configured" i
+
+files="$ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $ARCH_PUPPET_CONFIGURATION_SCRIPT"
+
+$SCRIPTS/send_and_run.tcl "$dest" "$password" "$git_branch" "$environment" $files
+
+### Installation finished
+if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
+  echo "Rebooting"
+  python $PYTHON_DIRECTORY/reboot_$T.py --local "$host_id"
+fi
diff --git a/bin/install_script_ovh_cloud_instance.sh b/bin/install_script_ovh_cloud_instance.sh
deleted file mode 100755 (executable)
index 26e410e..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-#!/bin/bash
-
-usage() {
-cat <<EOF
-  $0 [options]
-  --help,-h               This help
-  --instance-id id        Id of the instance
-  --reinstall-first       Start with reinstalling the vps
-  --host-user user        Use another user (default: arch)
-  --no-reboot             Don't reboot
-  --no-reboot-start       Don't reboot to rescue at the beginning
-  --no-reboot-end         Don't reboot to normal at the end
-  --git-branch            Use another puppet branch (default: master)
-  --environment           Environment to use for the installl (default: production)
-EOF
-}
-
-set -e
-
-host_user=arch
-git_branch=master
-environment=production
-
-while [ -n "$1" ]; do
-  case "$1" in
-    --instance-id)
-      instance_id="$2"
-      shift
-      ;;
-    --reinstall-first)
-      reinstall_first=1
-      ;;
-    --host-user)
-      host_user="$2"
-      shift
-      ;;
-    --no-reboot)
-      no_reboot=1
-      ;;
-    --no-reboot-start)
-      no_reboot_start=1
-      ;;
-    --no-reboot-end)
-      no_reboot_end=1
-      ;;
-    --git-branch)
-      git_branch="$2"
-      shift
-      ;;
-    --environment)
-      environment="$2"
-      shift
-      ;;
-    --help|-h)
-      usage
-      exit 0
-      ;;
-  esac
-
-  shift
-done
-
-DIRECTORY=$(cd `dirname $0` && pwd)
-PYTHON_DIRECTORY="$DIRECTORY/../python"
-
-if [ -z "$instance_id" ]; then
-  read -p "Id de l'instance : " instance_id
-fi
-
-if [ -n "$reinstall_first" ]; then
-  echo "Réinstallation du système"
-  python $PYTHON_DIRECTORY/reinstall_cloud_instance.py --use-current "$instance_id"
-
-  read -p "Appuyer sur une touche quand le serveur est prêt" ready
-fi
-
-if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
-  echo "Patienter le temps du reboot"
-  python $PYTHON_DIRECTORY/reboot_cloud_instance.py --rescue "$instance_id"
-
-  read -p "Appuyer sur une touche quand l'instance a redémarré" ready
-fi
-
-ARCH_DIR=`mktemp -d`
-ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh"
-ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh"
-ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh"
-ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh"
-ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
-
-trap "rm -rf $ARCH_DIR" EXIT
-
-#### Base installation stage
-python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id > $ARCH_PUPPET_INITIAL_CONFIGURATION
-host_address=$(python $PYTHON_DIRECTORY/get_initial_configuration_cloud_instance.py $instance_id | jq -r '.ips.v4.ipAddress')
-
-cat > $ARCH_HOST_SCRIPT <<EOF
-#!/bin/bash
-
-sudo haveged &
-sudo pacman -Sy --noconfirm arch-install-scripts
-
-DEVICE=/dev/vdb1
-MOUNTPOINT=/mnt
-
-UUID=\$(lsblk -rno UUID "\$DEVICE")
-PART="/dev/disk/by-uuid/\$UUID"
-
-# mkfs.ext4 -F -U "\$UUID" "\$DEVICE"
-sudo mount "\$DEVICE" /mnt
-
-##### FIXME: mkfs.ext4 would be better ####
-for i in /mnt/*; do
-  if [ "\$i" = "/mnt/boot" ]; then
-    # keep /boot/grub
-    sudo rm -f \$i/*
-  else
-    sudo rm -rf \$i
-  fi
-done
-##### /FIXME ####
-
-sudo pacstrap /mnt base git puppet
-
-echo "\$PART / auto defaults 0 1" | sudo tee /mnt/etc/fstab
-
-sudo cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/"
-sudo cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/"
-
-sudo arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh
-EOF
-
-cat > $ARCH_INSTALL_SCRIPT <<EOF
-CODE_PATH="/etc/puppetlabs/code"
-rm -rf \$CODE_PATH
-git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-# The password seed requires puppet to be run twice
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-EOF
-
-chmod a+x $ARCH_HOST_SCRIPT $ARCH_INSTALL_SCRIPT
-
-expect -f - <<EOF
-set timeout -1
-spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_HOST_SCRIPT $ARCH_INSTALL_SCRIPT $host_user@$host_address:/tmp
-expect eof
-spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$host_address /tmp/arch_host_script.sh
-expect eof
-EOF
-
-### Role specific stage
-read -p "Press key when LDAP is configured" i
-
-cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF
-CODE_PATH="/etc/puppetlabs/code"
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-EOF
-
-cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF
-MOUNTPOINT=/mnt
-
-sudo cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/"
-
-sudo arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh
-EOF
-
-chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT
-
-expect -f - <<EOF
-set timeout -1
-spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $host_user@$host_address:/tmp
-expect eof
-spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$host_address /tmp/arch_host_puppet_configuration_script.sh
-expect eof
-EOF
-
-### Installation finished
-if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
-  echo "Rebooting"
-  python $PYTHON_DIRECTORY/reboot_cloud_instance.py --local "$instance_id"
-fi
diff --git a/bin/install_script_ovh_vps_ssd.sh b/bin/install_script_ovh_vps_ssd.sh
deleted file mode 100755 (executable)
index 6b1aa39..0000000
+++ /dev/null
@@ -1,237 +0,0 @@
-#!/bin/bash
-
-usage() {
-cat <<EOF
-  $0 [options]
-  --help,-h               This help
-  --vps vps_name          Name of the vps
-  --password password     Password of the vps (only useful in case of no reboot)
-  --reinstall-first       Start with reinstalling the vps
-  --host-user user        Use another user (default: root)
-  --no-reboot             Don't reboot
-  --no-reboot-start       Don't reboot to rescue at the beginning
-  --no-reboot-end         Don't reboot to normal at the end
-  --git-branch            Use another puppet branch (default: master)
-  --environment           Environment to use for the installl (default: production)
-EOF
-}
-
-set -e
-
-host_user=root
-git_branch=master
-environment=production
-
-while [ -n "$1" ]; do
-  case "$1" in
-    --vps)
-      vps_name="$2"
-      shift
-      ;;
-    --reinstall-first)
-      reinstall_first=1
-      ;;
-    --password)
-      password="$2"
-      shift
-      ;;
-    --host-user)
-      host_user="$2"
-      shift
-      ;;
-    --no-reboot)
-      no_reboot=1
-      ;;
-    --no-reboot-start)
-      no_reboot_start=1
-      ;;
-    --no-reboot-end)
-      no_reboot_end=1
-      ;;
-    --git-branch)
-      git_branch="$2"
-      shift
-      ;;
-    --environment)
-      environment="$2"
-      shift
-      ;;
-    --help|-h)
-      usage
-      exit 0
-      ;;
-  esac
-
-  shift
-done
-
-DIRECTORY=$(cd `dirname $0` && pwd)
-PYTHON_DIRECTORY="$DIRECTORY/../python"
-
-if [ -z "$vps_name" ]; then
-  read -p "Nom du vps : " vps_name
-fi
-
-if [ -n "$reinstall_first" ]; then
-  echo "Réinstallation du système"
-  python $PYTHON_DIRECTORY/reinstall_vps_server.py --use-current "$vps_name"
-
-  read -p "Appuyer sur une touche quand le serveur est prêt" ready
-fi
-
-if [ -z "$no_reboot" -a -z "$no_reboot_start" ]; then
-  echo "Patienter le temps du reboot"
-  python $PYTHON_DIRECTORY/reboot_vps_server.py --rescue "$vps_name"
-fi
-
-if [ -z "$password" ]; then
-  stty -echo
-  read -p "Mot de passe reçu par e-mail : " password; echo
-  stty echo
-fi
-
-ARCH_DIR=`mktemp -d`
-ARCH_HOST_SCRIPT="$ARCH_DIR/arch_host_script.sh"
-ARCH_CHROOT_SCRIPT="$ARCH_DIR/arch_chroot_script.sh"
-ARCH_INSTALL_SCRIPT="$ARCH_DIR/arch_install_script.sh"
-ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_host_puppet_configuration_script.sh"
-ARCH_PUPPET_CONFIGURATION_SCRIPT="$ARCH_DIR/arch_puppet_configuration_script.sh"
-ARCH_PUPPET_INITIAL_CONFIGURATION="$ARCH_DIR/puppet_variables.json"
-
-trap "rm -rf $ARCH_DIR" EXIT
-
-#### Base installation stage
-python $PYTHON_DIRECTORY/get_initial_configuration.py $vps_name > $ARCH_PUPPET_INITIAL_CONFIGURATION
-
-cat > $ARCH_HOST_SCRIPT <<EOF
-#!/bin/bash
-
-apt-get update
-apt-get install -y haveged
-haveged &
-
-cd /tmp
-
-LATEST=\$(curl https://mirrors.kernel.org/archlinux/iso/latest/sha1sums.txt | grep "bootstrap" | head -n1)
-SHA1=\$(echo "\$LATEST" | cut -d' ' -f1)
-NAME=\$(echo "\$LATEST" | cut -d' ' -f3)
-
-curl -O "https://mirrors.kernel.org/archlinux/iso/latest/\$NAME"
-
-tar -xzf "\$NAME"
-
-echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/\$repo/os/\$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist
-
-DEVICE_STR=\$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
-DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1)
-MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2)
-
-umount "\$DEVICE"
-UUID=\$(lsblk -rno UUID "\$DEVICE")
-
-echo "\$UUID" > /tmp/root.x86_64/device_uuid
-
-cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/
-
-/tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ /arch_chroot_script.sh
-
-mount "\$DEVICE"
-
-cp /tmp/arch_install_script.sh "\$MOUNTPOINT/root/"
-cp /tmp/puppet_variables.json "\$MOUNTPOINT/root/"
-
-/tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_install_script.sh
-EOF
-
-
-cat > $ARCH_CHROOT_SCRIPT <<EOF
-#!/bin/bash
-
-pacman-key --init
-pacman-key --populate archlinux
-
-UUID=\$(cat /device_uuid)
-PART="/dev/disk/by-uuid/\$UUID"
-DEVICE=\$(realpath "\$PART")
-
-# mkfs.ext4 -F -U "\$UUID" "\$DEVICE"
-mount "\$DEVICE" /mnt
-
-##### FIXME: mkfs.ext4 would be better ####
-for i in /mnt/*; do
-  if [ "\$i" = "/mnt/boot" ]; then
-    # keep /boot/grub
-    rm -f \$i/*
-  else
-    rm -rf \$i
-  fi
-done
-##### /FIXME ####
-
-pacstrap /mnt base git puppet
-
-echo "\$PART / auto defaults 0 1" > /mnt/etc/fstab
-
-umount /mnt
-EOF
-
-cat > $ARCH_INSTALL_SCRIPT <<EOF
-CODE_PATH="/etc/puppetlabs/code"
-rm -rf \$CODE_PATH
-git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git \$CODE_PATH
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-# The password seed requires puppet to be run twice
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-EOF
-
-chmod a+x $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT
-
-expect -f - <<EOF
-set timeout -1
-spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_INITIAL_CONFIGURATION $ARCH_HOST_SCRIPT $ARCH_CHROOT_SCRIPT $ARCH_INSTALL_SCRIPT $host_user@$vps_name:/tmp
-expect "assword:"
-send "$password\n"
-expect eof
-spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_script.sh
-expect "assword:"
-send "$password\r"
-expect eof
-EOF
-
-### Role specific stage
-read -p "Press key when LDAP is configured" i
-
-cat > $ARCH_PUPPET_CONFIGURATION_SCRIPT <<EOF
-CODE_PATH="/etc/puppetlabs/code"
-puppet apply --environment $environment --tags base_installation --test \$CODE_PATH/manifests/site.pp
-EOF
-
-cat > $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT <<EOF
-DEVICE_STR=\$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
-DEVICE=\$(echo "\$DEVICE_STR" | cut -d' ' -f1)
-MOUNTPOINT=\$(echo "\$DEVICE_STR" | cut -d' ' -f2)
-
-cp /tmp/arch_puppet_configuration_script.sh "\$MOUNTPOINT/root/"
-
-/tmp/root.x86_64/bin/arch-chroot "\$MOUNTPOINT" /root/arch_puppet_configuration_script.sh
-EOF
-
-chmod a+x $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT
-
-expect -f - <<EOF
-set timeout -1
-spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $ARCH_PUPPET_CONFIGURATION_SCRIPT $ARCH_HOST_PUPPET_CONFIGURATION_SCRIPT $host_user@$vps_name:/tmp
-expect "assword:"
-send "$password\n"
-expect eof
-spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no $host_user@$vps_name /tmp/arch_host_puppet_configuration_script.sh
-expect "assword:"
-send "$password\r"
-expect eof
-EOF
-
-### Installation finished
-if [ -z "$no_reboot" -a -z "$no_reboot_end" ]; then
-  echo "Rebooting"
-  python $PYTHON_DIRECTORY/reboot_vps_server.py --local "$vps_name"
-fi
index a71c6f361de36d1ee752b262c52d8d34c25b914b..9c79d3c8480bd6675c91d74bd495e3a08f64ac8e 100644 (file)
@@ -1,4 +1,4 @@
-#### Please add this node to LDAP:
+\e[0;35m#### Please add this node to LDAP:\e[0m
 ldapadd -D "cn=root,<%= @ldap_base %>" -W << 'EOF'
 dn: <%= @ldap_dn %>
 cn: <%= @ldap_cn %>
@@ -14,12 +14,13 @@ objectclass: ipHost
 environment: <%= @environment %>
 userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %>
 EOF
-#### Or modify an existing entry:
+\e[0;35m#### Or modify an existing entry:\e[0m
 ldapmodify -D "cn=root,<%= @ldap_base %>" -W << 'EOF'
 dn: <%= @ldap_dn %>
 changetype: modify
 replace: userPassword
 userpassword: {SSHA}<%= Base64.encode64(Digest::SHA1.digest(@ldap_password+@ssha_ldap_seed)+@ssha_ldap_seed).chomp! %>
+-
 replace: environment
 environment: <%= @environment %>
 <%- unless @ips.empty? -%>
similarity index 52%
rename from python/get_initial_configuration_cloud_instance.py
rename to python/get_initial_configuration_ovh_cloud_instance.py
index 41577163e96fe95f43d9993e59625e0a6f0a210c..844373c3a519ae2ae3f206a1040e92543ea9e854 100644 (file)
@@ -6,6 +6,7 @@ except ImportError:
     # In case it's installed globally
     import ovh
 import sys
+from ovh_helper import find_cloud_instance
 
 infos = {}
 
@@ -13,19 +14,7 @@ infos = {}
 # See ovh/README.rst
 client = ovh.Client()
 
-projects_list = client.get('/cloud/project/')
-if len(projects_list) > 1:
-    print("More than one project is not supported, taking the first one")
-project = projects_list[0]
-instances_list = client.get('/cloud/project/{}/instance'.format(project))
-instances = dict(map(lambda x: (x["id"], x), instances_list))
-if sys.argv[-1] in instances:
-    instance = instances[sys.argv[-1]]
-else:
-    print("Instance not in list:")
-    for instance in instances_list:
-        print("{}: {}".format(instance["name"], instance["id"]))
-    sys.exit(1)
+_, instance = find_cloud_instance(client, sys.argv[-1])
 
 infos["ips"] = {}
 for ip_infos in instance["ipAddresses"]:
index 9b8bc64b5362c9cbb669a47c4e0dbdab244ba105..e7bd2af9a27ed5c5a205dc60678a77bffd30da10 100644 (file)
@@ -6,7 +6,18 @@ except ImportError:
 
 client = ovh.Client()
 
+print("OVH cloud instances:")
+projects_list = client.get('/cloud/project/')
+for project_id in projects_list:
+    project = client.get('/cloud/project/{}'.format(project_id))
+    print("\t{}:".format(project["description"]))
+    instances_list = client.get('/cloud/project/{}/instance'.format(project_id))
+    for instance in instances_list:
+        print("\t\t{}: {}".format(instance["name"], instance["id"]))
+
 vps_list = client.get('/vps/')
 
+print("OVH VPS SSD servers:")
 for vps in vps_list:
-    print(vps)
+    print("\t{}".format(vps))
+
index a49a245ae7233e93a500bdbd844906de2f18599b..19834ae2004508da78c2928f80f03872e2b5476c 100644 (file)
@@ -1,4 +1,5 @@
 import time
+import sys
 
 def show_progress(client, vps, task_type):
     running_task_id = client.get("/vps/{}/tasks?type={}".format(vps, task_type))[0]
@@ -17,3 +18,19 @@ def show_progress(client, vps, task_type):
         time.sleep(3)
 
     print("\rFinished")
+
+def find_cloud_instance(client, instance_id):
+    projects_list = client.get('/cloud/project/')
+    instances_list = []
+    for project in projects_list:
+        instances_list += list(map(lambda x: [project, x],
+                client.get('/cloud/project/{}/instance'.format(project))))
+    instances = dict(map(lambda x: (x[1]["id"], x), instances_list))
+    if instance_id in instances:
+        project_instance = instances[instance_id]
+    else:
+        print("Instance not in list:")
+        for instance in instances_list:
+            print("{}: {}".format(instance[1]["name"], instance[1]["id"]))
+        sys.exit(1)
+    return project_instance
similarity index 52%
rename from python/reboot_cloud_instance.py
rename to python/reboot_ovh_cloud_instance.py
index b90f488826c0243f9c233a2cf469dc822d069c1f..de20c07c1a905789f5c129ec797c0626de664efd 100644 (file)
@@ -6,24 +6,13 @@ except ImportError:
     # In case it's installed globally
     import ovh
 import sys
+from ovh_helper import find_cloud_instance
 
 # Credentials are stored in ~/.ovh.conf
 # See ovh/README.rst
 client = ovh.Client()
 
-projects_list = client.get('/cloud/project/')
-if len(projects_list) > 1:
-    print("More than one project is not supported, taking the first one")
-project = projects_list[0]
-instances_list = client.get('/cloud/project/{}/instance'.format(project))
-instances = dict(map(lambda x: (x["id"], x), instances_list))
-if sys.argv[-1] in instances:
-    instance = instances[sys.argv[-1]]
-else:
-    print("Instance not in list:")
-    for instance in instances_list:
-        print("{}: {}".format(instance["name"], instance["id"]))
-    sys.exit(1)
+project, instance = find_cloud_instance(client, sys.argv[-1])
 
 if "--rescue" in sys.argv:
     netboot_mode="rescue"
similarity index 71%
rename from python/reinstall_cloud_instance.py
rename to python/reinstall_ovh_cloud_instance.py
index c488fda23f4de2d3e408f14a476a492e46821bc8..c0d26174821bf7e0bb4a13b86371b55a2d85765d 100644 (file)
@@ -6,24 +6,13 @@ except ImportError:
     # In case it's installed globally
     import ovh
 import sys
+from ovh_helper import find_cloud_instance
 
 # Credentials are stored in ~/.ovh.conf
 # See ovh/README.rst
 client = ovh.Client()
 
-projects_list = client.get('/cloud/project/')
-if len(projects_list) > 1:
-    print("More than one project is not supported, taking the first one")
-project = projects_list[0]
-instances_list = client.get('/cloud/project/{}/instance'.format(project))
-instances = dict(map(lambda x: (x["id"], x), instances_list))
-if sys.argv[-1] in instances:
-    instance = instances[sys.argv[-1]]
-else:
-    print("Instance not in list:")
-    for instance in instances_list:
-        print("{}: {}".format(instance["name"], instance["id"]))
-    sys.exit(1)
+project, instance = find_cloud_instance(client, sys.argv[-1])
 
 current_image = instance["imageId"]
 available_images = client.get('/cloud/project/{}/image'.format(project),
diff --git a/scripts/arch_install_script.sh b/scripts/arch_install_script.sh
new file mode 100755 (executable)
index 0000000..21e202f
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+git_branch="$1"
+environment="$2"
+CODE_PATH="/etc/puppetlabs/code"
+
+rm -rf $CODE_PATH
+
+git clone -b $git_branch --recursive https://git.immae.eu/perso/Immae/Projets/Puppet.git $CODE_PATH
+puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp
+# The password seed requires puppet to be run twice
+puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp
+
diff --git a/scripts/arch_puppet_configuration_script.sh b/scripts/arch_puppet_configuration_script.sh
new file mode 100755 (executable)
index 0000000..caf8987
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+git_branch="$1"
+environment="$2"
+CODE_PATH="/etc/puppetlabs/code"
+
+puppet apply --environment $environment --tags base_installation --test $CODE_PATH/manifests/site.pp
+
diff --git a/scripts/ovh_cloud_instance/arch_host_puppet_configuration_script.sh b/scripts/ovh_cloud_instance/arch_host_puppet_configuration_script.sh
new file mode 100755 (executable)
index 0000000..b58e255
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+git_branch="$1"
+environment="$2"
+
+MOUNTPOINT=/mnt
+
+sudo cp /tmp/arch_puppet_configuration_script.sh "$MOUNTPOINT/root/"
+
+sudo arch-chroot "$MOUNTPOINT" /root/arch_puppet_configuration_script.sh "$git_branch" "$environment"
+
diff --git a/scripts/ovh_cloud_instance/arch_host_script.sh b/scripts/ovh_cloud_instance/arch_host_script.sh
new file mode 100755 (executable)
index 0000000..3408563
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+set -e
+
+git_branch="$1"
+environment="$2"
+
+# Randomizer
+sudo haveged &
+# /Randomizer
+
+# Prepare an arch chroot
+sudo pacman -Sy --noconfirm arch-install-scripts
+# /Prepare an arch chroot
+
+# Prepare device information
+DEVICE=/dev/vdb1
+MOUNTPOINT=/mnt
+
+UUID=$(lsblk -rno UUID "$DEVICE")
+PART="/dev/disk/by-uuid/$UUID"
+# /Prepare device information
+
+# Install very basic system (base git puppet)
+# mkfs.ext4 -F -U "$UUID" "$DEVICE"
+sudo mount "$DEVICE" /mnt
+
+##### FIXME: mkfs.ext4 would be better ####
+for i in /mnt/*; do
+  if [ "$i" = "/mnt/boot" ]; then
+    # keep /boot/grub
+    sudo rm -f $i/* || true
+  else
+    sudo rm -rf $i
+  fi
+done
+##### /FIXME ####
+
+sudo pacstrap /mnt base git puppet
+
+echo "$PART / auto defaults 0 1" | sudo tee /mnt/etc/fstab
+# /Install very basic system
+
+# Install rest of system (via puppet)
+sudo cp /tmp/arch_install_script.sh "$MOUNTPOINT/root/"
+sudo cp /tmp/puppet_variables.json "$MOUNTPOINT/root/"
+
+sudo arch-chroot "$MOUNTPOINT" /root/arch_install_script.sh "$git_branch" "$environment"
+# /Install rest of system
+
diff --git a/scripts/ovh_vps_ssd/arch_chroot_script.sh b/scripts/ovh_vps_ssd/arch_chroot_script.sh
new file mode 100755 (executable)
index 0000000..9dc5c46
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+pacman-key --init
+pacman-key --populate archlinux
+
+UUID=$(cat /device_uuid)
+PART="/dev/disk/by-uuid/$UUID"
+DEVICE=$(realpath "$PART")
+
+# mkfs.ext4 -F -U "$UUID" "$DEVICE"
+mount "$DEVICE" /mnt
+
+##### FIXME: mkfs.ext4 would be better ####
+for i in /mnt/*; do
+  if [ "$i" = "/mnt/boot" ]; then
+    # keep /boot/grub
+    rm -f $i/*
+  else
+    rm -rf $i
+  fi
+done
+##### /FIXME ####
+
+pacstrap /mnt base git puppet
+
+echo "$PART / auto defaults 0 1" > /mnt/etc/fstab
+
+umount /mnt
+
diff --git a/scripts/ovh_vps_ssd/arch_host_puppet_configuration_script.sh b/scripts/ovh_vps_ssd/arch_host_puppet_configuration_script.sh
new file mode 100755 (executable)
index 0000000..dab8fac
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+git_branch="$1"
+environment="$2"
+
+DEVICE_STR=$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
+DEVICE=$(echo "$DEVICE_STR" | cut -d' ' -f1)
+MOUNTPOINT=$(echo "$DEVICE_STR" | cut -d' ' -f2)
+
+cp /tmp/arch_puppet_configuration_script.sh "$MOUNTPOINT/root/"
+
+/tmp/root.x86_64/bin/arch-chroot "$MOUNTPOINT" /root/arch_puppet_configuration_script.sh "$git_branch" "$environment"
+
diff --git a/scripts/ovh_vps_ssd/arch_host_script.sh b/scripts/ovh_vps_ssd/arch_host_script.sh
new file mode 100755 (executable)
index 0000000..8eecae4
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+set -e
+
+git_branch="$1"
+environment="$2"
+
+# Randomizer
+apt-get update
+apt-get install -y haveged
+haveged &
+# /Randomizer
+
+# Prepare an arch chroot
+cd /tmp
+
+LATEST=$(curl -L https://mirrors.kernel.org/archlinux/iso/latest/sha1sums.txt | grep "bootstrap" | head -n1)
+SHA1=$(echo "$LATEST" | cut -d' ' -f1)
+NAME=$(echo "$LATEST" | cut -d' ' -f3)
+
+curl -L -O "https://mirrors.kernel.org/archlinux/iso/latest/$NAME"
+
+tar -xzf "$NAME"
+
+echo 'Server = http://archlinux.mirrors.ovh.net/archlinux/$repo/os/$arch' > /tmp/root.x86_64/etc/pacman.d/mirrorlist
+# /Prepare an arch chroot
+
+# Prepare device information (not available in chroot)
+DEVICE_STR=$(cat /proc/mounts | grep "/dev/[sv]d.. /mnt/")
+DEVICE=$(echo "$DEVICE_STR" | cut -d' ' -f1)
+MOUNTPOINT=$(echo "$DEVICE_STR" | cut -d' ' -f2)
+
+umount "$DEVICE"
+UUID=$(lsblk -rno UUID "$DEVICE")
+
+echo "$UUID" > /tmp/root.x86_64/device_uuid
+# /Prepare device information
+
+# Install very basic system via chroot (base git puppet)
+cp /tmp/arch_chroot_script.sh /tmp/root.x86_64/
+
+/tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ /arch_chroot_script.sh
+# /Install very basic system via chroot
+
+# Mount and install rest of system (via puppet)
+mount "$DEVICE"
+
+cp /tmp/arch_install_script.sh "$MOUNTPOINT/root/"
+cp /tmp/puppet_variables.json "$MOUNTPOINT/root/"
+
+/tmp/root.x86_64/bin/arch-chroot "$MOUNTPOINT" /root/arch_install_script.sh "$git_branch" "$environment"
+# /Mount and install rest of system
+
diff --git a/scripts/send_and_run.tcl b/scripts/send_and_run.tcl
new file mode 100755 (executable)
index 0000000..42fae62
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/expect -f
+set dest [lindex $argv 0]
+set password [lindex $argv 1]
+set git_branch [lindex $argv 2]
+set environment [lindex $argv 3]
+set script [lindex $argv 4]
+set files [lrange $argv 4 end]
+
+if {$password == "x"} {
+  set ask_password 0
+} else {
+  set ask_password 1
+}
+
+set scriptname [file tail $script]
+
+set sshopts [split "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no"]
+
+set timeout -1
+spawn scp {*}$sshopts {*}$files $dest:/tmp
+if {$ask_password} {
+  expect "assword:"
+  send "$password\n"
+}
+expect eof
+spawn ssh {*}$sshopts $dest /tmp/$scriptname $git_branch $environment
+if {$ask_password} {
+  expect "assword:"
+  send "$password\n"
+}
+expect eof