diff --git a/host-puppet-conf-test b/host-puppet-conf-test new file mode 100755 index 0000000..e72008c --- /dev/null +++ b/host-puppet-conf-test @@ -0,0 +1,44 @@ +#!/bin/bash +set +x +HOSTNAME=$1 +PUPPET_ARGS=$2 + +if [ -z "$HOSTNAME" ]; then + echo "Usage: $0 fqdn" + exit 1 +fi + +if [ ! -d "$HOSTNAME" ]; then + echo "$0: No host-directory for '$HOSTNAME' found - execute in top-level cosmos dir" + exit 1 +fi + +PUPPET_ARGS=${PUPPET_ARGS-"--verbose"} + +# Check if cosmos or puppet is already running on host +echo "Checking if puppet or cosmos is already running..." +ssh root@$HOSTNAME ps aux | egrep -v "grep|edit-secrets|gpg-agent" | egrep -q "cosmos|puppet" + +if [ $? -eq 1 ] +then + echo "Copying files to host..." + rsync -av --exclude '*~' global/overlay/etc/puppet/cosmos-rules.yaml root@$HOSTNAME:/etc/puppet/cosmos-rules.yaml + rsync -av --exclude '*~' global/overlay/etc/puppet/manifests/cosmos-site.pp root@$HOSTNAME:/etc/puppet/manifests/cosmos-site.pp + rsync -av --exclude '*~' global/overlay/etc/puppet/cosmos-db.yaml root@$HOSTNAME:/etc/puppet/cosmos-db.yaml + rsync -av --exclude '*~' global/overlay/etc/hiera/data/common.yaml root@$HOSTNAME:/etc/hiera/data/common.yaml + + # Test if the user has symlinked puppet-sunet correctly + # by first checking if the link exits and then whether + # or not the directory contains any files. + if [ -L global/overlay/etc/puppet/cosmos-modules/sunet ] && \ + [ -n "$(ls -A global/overlay/etc/puppet/cosmos-modules/sunet/*)" ] + then + rsync -av --delete --exclude '*~' global/overlay/etc/puppet/cosmos-modules/sunet/* root@$HOSTNAME:/etc/puppet/cosmos-modules/sunet/. + fi + + echo "Running puppet apply..." + ssh root@$HOSTNAME /usr/bin/puppet apply $PUPPET_ARGS /etc/puppet/manifests/cosmos-site.pp +else + echo "Cosmos or puppet already running. Exiting." + exit 1 +fi diff --git a/prepair-iaas-debian b/prepair-iaas-debian new file mode 100755 index 0000000..d368e6a --- /dev/null +++ b/prepair-iaas-debian @@ -0,0 +1,24 @@ +#!/bin/bash +ip="${1}" + +if [[ -z "${ip}" ]]; then + echo "Please specify a cloud image host that the script should do the following on:" + echo " #1 enable root-login" + echo " #2 remove the default user" + echo " #3 run apt-get update and dist-upgrade without interaction" + echo " #4 reboot to start using the new kernel, updated packages etc." + exit 1 +fi + +set -x + +ssh "debian@${ip}" sudo cp -r /home/debian/.ssh /root/ +ssh "debian@${ip}" sudo chown -R root:root /root/.ssh +ssh "debian@${ip}" sudo chmod 700 /root/.ssh +ssh "debian@${ip}" sudo chmod 600 /root/.ssh/authorized_keys +ssh "root@${ip}" deluser debian +ssh "root@${ip}" rm /home/debian -rf +ssh "root@${ip}" rm /etc/sudoers.d/* +ssh "root@${ip}" DEBIAN_FRONTEND="noninteractive" apt-get -y update +ssh "root@${ip}" DEBIAN_FRONTEND="noninteractive" apt-get -o Dpkg::Options::="--force-confnew" --fix-broken --assume-yes dist-upgrade +ssh "root@${ip}" reboot diff --git a/prepair-iaas-ubuntu b/prepair-iaas-ubuntu new file mode 100755 index 0000000..3fdff8d --- /dev/null +++ b/prepair-iaas-ubuntu @@ -0,0 +1,24 @@ +#!/bin/bash +ip="${1}" + +if [[ -z "${ip}" ]]; then + echo "Please specify a cloud image host that the script should do the following on:" + echo " #1 enable root-login" + echo " #2 remove the default user" + echo " #3 run apt-get update and dist-upgrade without interaction" + echo " #4 reboot to start using the new kernel, updated packages etc." + exit 1 +fi + +set -x + +ssh "ubuntu@${ip}" sudo cp -r /home/ubuntu/.ssh /root/ +ssh "ubuntu@${ip}" sudo chown -R root:root /root/.ssh +ssh "ubuntu@${ip}" sudo chmod 700 /root/.ssh +ssh "ubuntu@${ip}" sudo chmod 600 /root/.ssh/authorized_keys +ssh "root@${ip}" deluser ubuntu +ssh "root@${ip}" rm /home/ubuntu -rf +ssh "root@${ip}" rm /etc/sudoers.d/* +ssh "root@${ip}" DEBIAN_FRONTEND="noninteractive" apt-get -y update +ssh "root@${ip}" DEBIAN_FRONTEND="noninteractive" apt-get -o Dpkg::Options::="--force-confnew" --fix-broken --assume-yes dist-upgrade +ssh "root@${ip}" reboot