Skip to content

Instantly share code, notes, and snippets.

@ravibhure
Last active May 19, 2017 05:52
Show Gist options
  • Save ravibhure/3bc92132dbff8143df248087c3911617 to your computer and use it in GitHub Desktop.
Save ravibhure/3bc92132dbff8143df248087c3911617 to your computer and use it in GitHub Desktop.
Bootstrap for ansiblized node
#!/bin/bash
# Bootstrap for ansiblized node
# Author: Ravi Bhure <[email protected]>
# Usages: curl -L https://raw.githubusercontent.com/ravibhure/terraform-provisioner-ansible/master/bootstrap_ansible_node.sh | sudo bash
machine=`uname -m`
os=`uname -s`
if test -f "/etc/lsb-release" && grep -q DISTRIB_ID /etc/lsb-release && ! grep -q wrlinux /etc/lsb-release; then
platform=`grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr '[A-Z]' '[a-z]'`
platform_version=`grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2`
if test "x$platform" = "xubuntu" ; then
apt-get -qq update
apt-get -qq -y install software-properties-common
apt-add-repository -y ppa:ansible/ansible
apt-get -qq update
apt-get -qq -y install ansible
fi
elif test -f "/etc/debian_version"; then
platform="debian"
platform_version=`cat /etc/debian_version`
apt-get -qq update
apt-get -qq -y install software-properties-common
apt-add-repository -y ppa:ansible/ansible
apt-get -qq update
apt-get -qq -y install ansible
elif test -f "/etc/redhat-release"; then
platform=`sed 's/^\(.\+\) release.*/\1/' /etc/redhat-release | tr '[A-Z]' '[a-z]'`
platform_version=`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release`
# If /etc/redhat-release exists, we act like RHEL by default
# FIXME: stop remapping fedora to el
# FIXME: remove client side platform_version mangling and hard coded yolo
# Change platform version for use below.
platform_version="6.0"
yum -y update > /dev/null 2>&1
yum -q -y install epel-release
yum-config-manager --enable epel > /dev/null 2>&1
yum repolist all > /dev/null 2>&1
yum -q -y install ansible
ret=`python -c 'import sys; print("%i" % (sys.hexversion<0x03000000))'`
if test "x$ret" != "x0" ; then
yum -q -y install python-argparse python-jinja2
fi
elif test -f "/etc/system-release"; then
platform=`sed 's/^\(.\+\) release.\+/\1/' /etc/system-release | tr '[A-Z]' '[a-z]'`
platform_version=`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/system-release | tr '[A-Z]' '[a-z]'`
# amazon is built off of fedora, so act like RHEL
if test "$platform" = "amazon linux ami"; then
# FIXME: remove client side platform_version mangling and hard coded yolo, and remapping to deprecated "el"
platform="el"
platform_version="6.0"
yum -y update > /dev/null 2>&1
yum -q -y install epel-release
yum-config-manager --enable epel > /dev/null 2>&1
yum repolist all > /dev/null 2>&1
yum -q -y install ansible
ret=`python -c 'import sys; print("%i" % (sys.hexversion<0x03000000))'`
if test "x$ret" != "x0" ; then
yum -q -y install python-argparse python-jinja2
fi
fi
# Apple OS X
elif test -f "/usr/bin/sw_vers"; then
platform="mac_os_x"
# Matching the tab-space with sed is error-prone
platform_version=`sw_vers | awk '/^ProductVersion:/ { print $2 }' | cut -d. -f1,2`
# x86_64 Apple hardware often runs 32-bit kernels (see OHAI-63)
x86_64=`sysctl -n hw.optional.x86_64`
if test $x86_64 -eq 1; then
machine="x86_64"
fi
elif test -f "/etc/release"; then
machine=`/usr/bin/uname -p`
if grep -q SmartOS /etc/release; then
platform="smartos"
platform_version=`grep ^Image /etc/product | awk '{ print $3 }'`
else
platform="solaris2"
platform_version=`/usr/bin/uname -r`
fi
elif test -f "/etc/SuSE-release"; then
if grep -q 'Enterprise' /etc/SuSE-release;
then
platform="sles"
platform_version=`awk '/^VERSION =/ { print $3 }' /etc/SuSE-release`
if test "x$platform_version" = "x10" ;then
zypper --quiet --non-interactive ar http://download.opensuse.org/repositories/systemsmanagement/SLE_10_SDK/systemsmanagement.repo
elif test "x$platform_version" = "x11" ;then
zypper --quiet --non-interactive ar http://download.opensuse.org/repositories/systemsmanagement/SLE_11_SP4/systemsmanagement.repo
elif test "x$platform_version" = "x12" ;then
zypper --quiet --non-interactive ar http://download.opensuse.org/repositories/systemsmanagement/SLE_12/systemsmanagement.repo
fi
zypper --quiet --non-interactive refresh
zypper --quiet --non-interactive install ansible
else
platform="suse"
platform_version=`awk '/^VERSION =/ { print $3 }' /etc/SuSE-release`
if test "x$platform_version" = "x10" ;then
zypper --quiet --non-interactive ar http://download.opensuse.org/repositories/systemsmanagement/SLE_10_SDK/systemsmanagement.repo
elif test "x$platform_version" = "x11" ;then
zypper --quiet --non-interactive ar http://download.opensuse.org/repositories/systemsmanagement/SLE_11_SP4/systemsmanagement.repo
elif test "x$platform_version" = "x12" ;then
zypper --quiet --non-interactive ar http://download.opensuse.org/repositories/systemsmanagement/SLE_12/systemsmanagement.repo
fi
zypper --quiet --non-interactive refresh
zypper --quiet --non-interactive install ansible
fi
elif test "x$os" = "xFreeBSD"; then
platform="freebsd"
platform_version=`uname -r | sed 's/-.*//'`
elif test "x$os" = "xAIX"; then
platform="aix"
platform_version="`uname -v`.`uname -r`"
machine="powerpc"
elif test -f "/etc/os-release"; then
. /etc/os-release
if test "x$CISCO_RELEASE_INFO" != "x"; then
. $CISCO_RELEASE_INFO
fi
platform=$ID
platform_version=$VERSION
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment