-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeploy-local-env.sh
156 lines (125 loc) · 4.24 KB
/
deploy-local-env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
#
# Bootstrap the environment on a given host and update with
# that latest configuration.
#
# see usage() below for script usage
#
# THIS SCRIPT MUST BE ENTIRELY SELF-CONTAINED! Do not use any other script.
################################################################################
# output message to STDERR and exit program
function ss_die() {
echo -e "ERROR: $*" >&2;
exit -1
}
# announce a section
function ss_announce()
{
echo -e "\n########################################"
echo -e "$1"
echo -e "########################################\n"
return 0;
}
# provide status output
function ss_status() { echo -e "# -- $1"; return 0; }
# provide warning output
function ss_warn() { echo -e "# -- WARNING: $1"; return 0; }
# display program usage and exit
function usage
{
cat <<EOF
Usage: deploy-local-env.sh [ansible command line args]
This script sets up the environment on a non Vagrant managed host.
This script performs the following functions:
1) Installs pip (if missing)
2) Installs ansible (if missing or wrong version)
3) Sets up a symlink in the root directory to allow the playbooks to access the
filestore in the same manner as they do in the VM
4) Configure the host using Ansible
This scripts will pass any arguments directly to the ansible-playbook command
EOF
exit 1
}
################################################################################
# DEFAULTS
################################################################################
# Version of Ansible to install
REQ_ANSIBLE_VER="2.9.13"
################################################################################
# PROCESS OPTIONS
################################################################################
# Left in script for now in case we want to add overrides in the future
#[[ 1 -le $# ]] || usage
#CNE_HOSTNAME="$1"
#[[ $CNE_HOSTNAME = -* ]] && usage
#shift 1
# process options - see getopt documentation for what this is doing
#set +e
#TEMP=`getopt -o b:p:h \
# -n "$(basename $0)" -- "$@"`
#[ $? == 0 ] || usage
#set -e
#eval set -- "$TEMP"
#while true ; do
# case "$1" in
# -p) ANSIBLE_PLAYBOOK="$2"; shift 2 ;;
# -b) BRANCH_NAME="$2" ; shift 2 ;;
# -h|--help) usage ; shift ;;
# --) shift ; break ;;
# *) echo "Internal error '$1' '$2'!" ; exit 1 ;;
# esac
#done
################################################################################
# CHECKS
################################################################################
################################################################################
# MAIN LOGIC
################################################################################
ss_announce "Installing Dependencies"
if [ -f "/etc/debian_version" ]; then
EXTRA_VARS="OS=ubuntu"
which pip >/dev/null 2>&1
PIP_INSTALLED=$?
if [[ $PIP_INSTALLED -eq 0 ]]; then
ss_status "pip already installed"
else
sudo apt install -y python3-pip
sudo pip3 install --upgrade pip
sudo pip3 install markupsafe typing ansible==2.9.13
fi
else
EXTRA_VARS="OS=rocky"
which pip >/dev/null 2>&1
PIP_INSTALLED=$?
if [[ $PIP_INSTALLED -eq 0 ]]; then
ss_status "pip already installed"
else
# Add repository that hosts package
ss_status "Installing pip"
sudo yum install -y epel-release
sudo yum -y update
sudo yum install -y python3-pip
sudo pip3 install --upgrade 'pip<21.0'
sudo pip3 install markupsafe typing ansible==2.9.13
fi
fi
####################
ANSIBLE_INFO=$(pip show ansible 2>/dev/null | grep -E "^Version:")
if [[ "Version: $REQ_ANSIBLE_VER" == "$ANSIBLE_INFO" ]]; then
ss_status "ansible $REQ_ANSIBLE_VER already installed"
else
ss_status "Installing ansible"
sudo -H pip3 install "ansible==$REQ_ANSIBLE_VER"
fi
####################
ss_status "Configure fileshare symlink at /vagrant"
sudo ln -sfn $(pwd)/ /vagrant
####################
ss_announce "Configuring environment"
ss_status "Running ansible playbook: ansible/base.yml"
ANSIBLE_CALLBACK_WHITELIST=profile_tasks \
ansible-playbook ansible/base.yml \
--ask-become-pass \
-i ansible/hosts.txt \
--extra-vars "$EXTRA_VARS" \
"$@" # we allow passtrough arguments from this script to ansible-playbook command