ansible-bootstrap.sh 3.99 KB
Newer Older
1 2 3 4 5 6 7 8
#!/usr/bin/env bash

#
# Script for installing Ansible and the edX configuration repostory
# onto a host to enable running ansible to complete configuration.
# This script can be used by Docker, Packer or any other system
# for building images that requires having ansible available.
#
Edward Zarecor committed
9 10
# Can be run as follows:
#
Edward Zarecor committed
11 12
# UPGRADE_OS=true CONFIGURATION_VERSION="master" \
# bash <(curl -s https://raw.githubusercontent.com/edx/configuration/master/util/install/ansible-bootstrap.sh)
13 14 15

set -xe

16
if [[ -z "${ANSIBLE_REPO}" ]]; then
17 18 19
  ANSIBLE_REPO="https://github.com/edx/ansible.git"
fi

20
if [[ -z "${ANSIBLE_VERSION}" ]]; then
21 22 23
  ANSIBLE_VERSION="master"
fi

24
if [[ -z "${CONFIGURATION_REPO}" ]]; then
25 26 27
  CONFIGURATION_REPO="https://github.com/edx/configuration.git"
fi

28
if [[ -z "${CONFIGURATION_VERSION}" ]]; then
Edward Zarecor committed
29
  CONFIGURATION_VERSION="master"
30 31
fi

32
if [[ -z "${UPGRADE_OS}" ]]; then
33 34 35
  UPGRADE_OS=false
fi

36 37 38
#
# Bootstrapping constants
#
Edward Zarecor committed
39
VIRTUAL_ENV_VERSION="13.1.2"
40 41
PIP_VERSION="7.1.2"
SETUPTOOLS_VERSION="18.3.2"
42 43 44 45
VIRTUAL_ENV="/tmp/bootstrap"
PYTHON_BIN="${VIRTUAL_ENV}/bin"
ANSIBLE_DIR="/tmp/ansible"
CONFIGURATION_DIR="/tmp/configuration"
46 47 48
EDX_PPA="deb http://ppa.edx.org precise main"
EDX_PPA_KEY_SERVER="pgp.mit.edu"
EDX_PPA_KEY_ID="69464050"
49 50 51 52

cat << EOF
******************************************************************************

53
Running the edx_ansible bootstrap script with the following arguments:
54 55 56 57 58 59 60 61 62 63

ANSIBLE_REPO="${ANSIBLE_REPO}"
ANSIBLE_VERSION="${ANSIBLE_VERSION}"
CONFIGURATION_REPO="${CONFIGURATION_REPO}"
CONFIGURATION_VERSION="${CONFIGURATION_VERSION}"

******************************************************************************
EOF


Edward Zarecor committed
64
if [[ $(id -u) -ne 0 ]] ;then
Edward Zarecor committed
65
    echo "Please run as root";
66 67 68
    exit 1;
fi

Edward Zarecor committed
69
if grep -q 'Precise Pangolin' /etc/os-release
Edward Zarecor committed
70 71 72 73 74 75
then
    SHORT_DIST="precise"
elif grep -q 'Trusty Tahr' /etc/os-release
then
    SHORT_DIST="trusty"
else    
76
    cat << EOF
77 78 79
    
    This script is only known to work on Ubuntu Precise and Trusty,
    exiting.  If you are interested in helping make installation possible
80
    on other platforms, let us know.
81

82 83 84 85
EOF
   exit 1;
fi

Edward Zarecor committed
86 87
EDX_PPA="deb http://ppa.edx.org ${SHORT_DIST} main"

88 89
# Upgrade the OS
apt-get update -y
Edward Zarecor committed
90
apt-key update -y
91

92
if [ "${UPGRADE_OS}" = true ]; then
93 94 95
    echo "Upgrading the OS..."
    apt-get upgrade -y
fi
96 97

# Required for add-apt-repository
Edward Zarecor committed
98
apt-get install -y software-properties-common python-software-properties
99

Edward Zarecor committed
100
# Add git PPA
Edward Zarecor committed
101
add-apt-repository -y ppa:git-core/ppa
Edward Zarecor committed
102 103

# Add python PPA
104 105
apt-key adv --keyserver "${EDX_PPA_KEY_SERVER}" --recv-keys "${EDX_PPA_KEY_ID}"
add-apt-repository -y "${EDX_PPA}"
Edward Zarecor committed
106

Edward Zarecor committed
107 108 109
# Install python 2.7 latest, git and other common requirements
# NOTE: This will install the latest version of python 2.7 and
# which may differ from what is pinned in virtualenvironments
110
apt-get update -y
Edward Zarecor committed
111
apt-get install -y build-essential sudo git-core python2.7 python2.7-dev python-pip python-apt python-yaml python-jinja2 libmysqlclient-dev
112

113
pip install --upgrade pip=="${PIP_VERSION}"
114 115 116

# pip moves to /usr/local/bin when upgraded
PATH=/usr/local/bin:${PATH}
117
pip install setuptools=="${SETUPTOOLS_VERSION}"
118
pip install virtualenv=="${VIRTUAL_ENV_VERSION}"
119 120

# create a new virtual env
121
/usr/local/bin/virtualenv "${VIRTUAL_ENV}"
122

123
PATH="${PYTHON_BIN}":${PATH}
124 125

# Install the configuration repository to install 
126
# edx_ansible role
127 128 129 130 131
git clone ${CONFIGURATION_REPO} ${CONFIGURATION_DIR}
cd ${CONFIGURATION_DIR}
git checkout ${CONFIGURATION_VERSION}
make requirements

132 133
cd "${CONFIGURATION_DIR}"/playbooks/edx-east
"${PYTHON_BIN}"/ansible-playbook edx_ansible.yml -i '127.0.0.1,' -c local -e "configuration_version=${CONFIGURATION_VERSION}"
134 135

# cleanup
136 137 138
rm -rf "${ANSIBLE_DIR}"
rm -rf "${CONFIGURATION_DIR}"
rm -rf "${VIRTUAL_ENV}"
139 140 141 142

cat << EOF
******************************************************************************

143
Done bootstrapping, edx_ansible is now installed in /edx/app/edx_ansible.
Edward Zarecor committed
144 145 146
Time to run some plays.  Activate the virtual env with 

> . /edx/app/edx_ansible/venvs/edx_ansible/bin/activate 
147 148 149 150

******************************************************************************
EOF