Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | |
| 3 | # bootstrap.sh |
| 4 | |
| 5 | # Installs Salt and configure minimal SaltMaster or Minion to be used with: |
| 6 | # - http://github.com/salt-formulas-scripts |
| 7 | # - http://github.com/salt-formulas/salt-formula-salt (salt.master sls) |
| 8 | |
Petr Michalec | b312004 | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 9 | # NOTE: This script is collection of shared functions to automate bootstrap of "salted" CI environments. |
| 10 | # Its not intended to be used in PRODUCTION unless you know what you are doing. |
| 11 | # You have been warned! |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 12 | |
azvyagintsev | e93f837 | 2018-09-12 16:50:58 +0300 | [diff] [blame] | 13 | __ScriptVersion="2018.09.12" |
| 14 | __ScriptName="bootstrap.sh" |
| 15 | __ScriptFullName="$0" |
| 16 | __ScriptArgs="$*" |
| 17 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 18 | # Source specific env vars. |
| 19 | # shopt -u dotglob |
| 20 | export RECLASS_ROOT=${RECLASS_ROOT:-/srv/salt/reclass} |
| 21 | function source_local_envs() { |
Petr Michalec | b444ef9 | 2017-08-17 13:53:14 +0200 | [diff] [blame] | 22 | for path in / /tmp/kitchen /srv/salt . ${RECLASS_ROOT}/classes/cluster ${RECLASS_ROOT}/classes/cluster/${CLUSTER_NAME}; do |
Vasyl Saienko | 7a4161c | 2017-08-14 17:43:15 +0300 | [diff] [blame] | 23 | for f in $(find $path -maxdepth 1 -name '*.env' 2> /dev/null); do |
| 24 | echo "Sourcing env variables from $f" |
| 25 | source $f |
| 26 | done |
| 27 | done |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 28 | } |
| 29 | source_local_envs |
| 30 | |
| 31 | ########################################## |
| 32 | # Set defaults env variables |
| 33 | |
| 34 | if [[ $DEBUG =~ ^(True|true|1|yes)$ ]]; then |
| 35 | set -x |
| 36 | SALT_LOG_LEVEL="--state-verbose=true -ldebug" |
| 37 | fi |
| 38 | |
| 39 | export MAGENTA='\033[0;95m' |
| 40 | export YELLOW='\033[1;33m' |
| 41 | export BLUE='\033[0;35m' |
| 42 | export CYAN='\033[0;96m' |
| 43 | export RED='\033[0;31m' |
| 44 | export NC='\033[0m' # No Color' |
| 45 | |
| 46 | export LC_ALL=C |
| 47 | export SALT_LOG_LEVEL="--state-verbose=false -lerror" |
| 48 | export SALT_OPTS="${SALT_OPTS:- --timeout=120 --state-output=changes --retcode-passthrough --force-color $SALT_LOG_LEVEL }" |
| 49 | export SALT_STATE_RETRY=${SALT_STATE_RETRY:-3} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 50 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 51 | # salt apt repository |
| 52 | test -e /etc/lsb-release && eval $(cat /etc/lsb-release) |
| 53 | which lsb_release && DISTRIB_CODENAME=${DISTRIB_CODENAME:-$(lsb_release -cs)} |
| 54 | # |
Dmitry Ukov | 95492a0 | 2017-10-23 11:34:45 +0400 | [diff] [blame] | 55 | export APT_REPOSITORY=${APT_REPOSITORY:- deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME} ${DISTRIB_REVISION:-stable} salt} |
chnyda | 30c07a6 | 2017-09-20 14:28:02 +0200 | [diff] [blame] | 56 | export APT_REPOSITORY_GPG=${APT_REPOSITORY_GPG:-http://apt.mirantis.com/public.gpg} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 57 | # reclass |
| 58 | export RECLASS_ADDRESS=${RECLASS_ADDRESS:-https://github.com/salt-formulas/openstack-salt.git} # https/git |
ibumarskov | f72e05e | 2017-11-29 14:37:48 +0300 | [diff] [blame] | 59 | export RECLASS_BRANCH=${RECLASS_BRANCH:-master} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 60 | |
| 61 | # formula |
| 62 | export FORMULAS_BASE=${FORMULAS_BASE:-https://github.com/salt-formulas} |
| 63 | export FORMULAS_PATH=${FORMULAS_PATH:-/usr/share/salt-formulas} |
| 64 | export FORMULAS_BRANCH=${FORMULAS_BRANCH:-master} |
| 65 | export FORMULAS_SOURCE=${FORMULAS_SOURCE:-pkg} # pkg/git |
Petr Michalec | 515356f | 2017-11-16 11:20:20 +0100 | [diff] [blame] | 66 | # Essential set of formulas (known to by used on cfg01 node for most setups during bootsrap) |
| 67 | # DEPRECATED: FORMULAS_SALT_MASTER=${FORMULAS_SALT_MASTER:- $EXTRA_FORMULAS maas memcached ntp nginx collectd sensu heka sphinx mysql grafana libvirt rsyslog glusterfs postfix xtrabackup freeipa prometheus telegraf elasticsearch kibana rundeck devops-portal rsync docker keepalived aptly jenkins gerrit artifactory influxdb horizon} |
azvyagintsev | e93f837 | 2018-09-12 16:50:58 +0300 | [diff] [blame] | 68 | FORMULAS_SALT_MASTER=${FORMULAS_SALT_MASTER:- "$EXTRA_FORMULAS"} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 69 | # minimal set of formulas for salt-master bootstrap |
azvyagintsev | e93f837 | 2018-09-12 16:50:58 +0300 | [diff] [blame] | 70 | declare -a FORMULAS_SALT_MASTER=(reclass salt git openssh linux $(echo "${FORMULAS_SALT_MASTER}")) |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 71 | export FORMULAS_SALT_MASTER |
| 72 | |
azvyagintsev | a7a91d5 | 2018-09-13 12:58:39 +0300 | [diff] [blame] | 73 | |
| 74 | # Install 'salt-formula-*'. Works only with FORMULAS_SOURCE==pkg |
| 75 | export EXTRA_FORMULAS_PKG_ALL=${EXTRA_FORMULAS_PKG_ALL:-False} |
| 76 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 77 | # system / host |
Petr Michalec | c749e86 | 2017-09-06 21:10:10 +0200 | [diff] [blame] | 78 | export HOSTNAME=${HOSTNAME:-`hostname -s`} |
| 79 | export HOSTNAME=${HOSTNAME//.*/} |
| 80 | export DOMAIN=${DOMAIN:-`hostname -d`} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 81 | export DOMAIN=${DOMAIN:-bootstrap.local} |
| 82 | |
| 83 | # salt |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 84 | export MINION_ID=${MINION_ID:-${HOSTNAME}.${DOMAIN}} |
Petr Michalec | 2e3a499 | 2017-08-17 14:20:43 +0200 | [diff] [blame] | 85 | export MASTER_HOSTNAME=${MASTER_HOSTNAME:-${HOSTNAME}.${DOMAIN}} |
azvyagintsev | e3f6f40 | 2018-08-23 17:21:49 +0300 | [diff] [blame] | 86 | # Ignore state.apply salt.master.env error |
| 87 | export SA_IGNORE_ERROR_SALT_MASTER_ENV=${SA_IGNORE_ERROR_SALT_MASTER_ENV:-False} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 88 | |
| 89 | # saltstack |
Petr Michalec | 33c0489 | 2017-09-08 15:10:30 +0200 | [diff] [blame] | 90 | BOOTSTRAP_SALTSTACK=${BOOTSTRAP_SALTSTACK:-True} |
alexz | 0adc271 | 2018-02-11 17:33:52 +0100 | [diff] [blame] | 91 | BOOTSTRAP_SALTSTACK_COM=${BOOTSTRAP_SALTSTACK_COM:-"https://bootstrap.saltstack.com"} |
Martin Polreich | 16673dd | 2018-04-20 12:08:56 +0200 | [diff] [blame] | 92 | BOOTSTRAP_SALTSTACK_VERSION=${BOOTSTRAP_SALTSTACK_VERSION:- stable 2017.7 } |
Jakub Josef | 0b61174 | 2018-01-09 17:02:01 +0100 | [diff] [blame] | 93 | BOOTSTRAP_SALTSTACK_VERSION=${BOOTSTRAP_SALTSTACK_VERSION//latest*/stable} |
alexz | 0adc271 | 2018-02-11 17:33:52 +0100 | [diff] [blame] | 94 | # TODO add 'r' option by default |
| 95 | # Currently, without 'r' option, upstream saltstack repos will be used. Otherwise |
| 96 | # local one should be used, from http://apt.mirantis.com/ or whatever. |
Petr Michalec | 33c0489 | 2017-09-08 15:10:30 +0200 | [diff] [blame] | 97 | BOOTSTRAP_SALTSTACK_OPTS=${BOOTSTRAP_SALTSTACK_OPTS:- -dX $BOOTSTRAP_SALTSTACK_VERSION } |
Petr Michalec | e11cf61 | 2017-09-08 18:21:48 +0200 | [diff] [blame] | 98 | SALT_SOURCE=${SALT_SOURCE:-pkg} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 99 | |
Petr Michalec | b312004 | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 100 | # SECURITY |
Petr Michalec | ca2471f | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 101 | SSH_STRICTHOSTKEYCHECKING=no |
Petr Michalec | b312004 | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 102 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 103 | # environment |
| 104 | if [ "$FORMULAS_SOURCE" == "git" ]; then |
| 105 | SALT_ENV=${SALT_ENV:-dev} |
| 106 | elif [ "$FORMULAS_SOURCE" == "pkg" ]; then |
| 107 | SALT_ENV=${SALT_ENV:-prd} |
| 108 | fi |
Petr Michalec | 05b5245 | 2017-09-08 14:26:59 +0200 | [diff] [blame] | 109 | eval "$(grep -h '=' /etc/*release 2> /dev/null)" |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 110 | PLATFORM_FAMILY=$(echo ${ID_LIKE// */} | tr A-Z a-z) |
| 111 | case $PLATFORM_FAMILY in |
| 112 | debian ) |
| 113 | PKGTOOL="$SUDO apt-get" |
| 114 | test ${VERSION_ID//\.*/} -ge 16 && { |
| 115 | SVCTOOL=service |
| 116 | } || { SVCTOOL=service |
| 117 | } |
| 118 | ;; |
| 119 | rhel ) |
| 120 | PKGTOOL="$SUDO yum" |
| 121 | test ${VERSION_ID//\.*/} -ge 7 && { |
| 122 | SVCTOOL=systemctl |
| 123 | } || { SVCTOOL=service |
| 124 | } |
| 125 | ;; |
| 126 | esac |
| 127 | |
| 128 | export PLATFORM_FAMILY |
| 129 | export PKGTOOL |
| 130 | export SVCTOOL |
| 131 | |
| 132 | ########################################## |
| 133 | # FUNCTIONS |
| 134 | |
| 135 | log_info() { |
| 136 | echo -e "${YELLOW}[INFO] $* ${NC}" |
| 137 | } |
| 138 | |
| 139 | log_warn() { |
| 140 | echo -e "${MAGENTA}[WARN] $* ${NC}" |
| 141 | } |
| 142 | |
Petr Michalec | 24b30e8 | 2017-08-21 10:59:18 +0200 | [diff] [blame] | 143 | log_debug() { |
| 144 | echo -e "${CYAN}[WARN] $* ${NC}" |
| 145 | } |
| 146 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 147 | log_err() { |
| 148 | echo -e "${RED}[ERROR] $* ${NC}" >&2 |
| 149 | } |
| 150 | |
| 151 | configure_pkg_repo() |
| 152 | { |
| 153 | |
| 154 | case $PLATFORM_FAMILY in |
| 155 | debian) |
| 156 | if [ -n "$APT_REPOSITORY_PPA" ]; then |
| 157 | which add-apt-repository || $SUDO apt-get install -y software-properties-common |
| 158 | $SUDO add-apt-repository -y ppa:${APT_REPOSITORY_PPA} |
| 159 | else |
Mykyta Karpin | fbcb548 | 2017-10-04 14:15:25 +0300 | [diff] [blame] | 160 | echo -e "$APT_REPOSITORY " | $SUDO tee /etc/apt/sources.list.d/mcp_salt.list >/dev/null |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 161 | curl -sL $APT_REPOSITORY_GPG | $SUDO apt-key add - |
| 162 | fi |
| 163 | $SUDO apt-get clean |
| 164 | $SUDO apt-get update |
| 165 | ;; |
| 166 | rhel) |
| 167 | $SUDO yum install -y https://repo.saltstack.com/yum/redhat/salt-repo-latest-1.el${VERSION_ID}.noarch.rpm |
| 168 | $SUDO yum clean all |
| 169 | ;; |
| 170 | esac |
| 171 | |
| 172 | } |
| 173 | |
| 174 | _atexit() { |
| 175 | RETVAL=$? |
| 176 | trap true INT TERM EXIT |
| 177 | |
| 178 | if [ $RETVAL -ne 0 ]; then |
| 179 | log_err "Execution failed" |
| 180 | else |
| 181 | log_info "Execution successful" |
| 182 | fi |
| 183 | return $RETVAL |
| 184 | } |
| 185 | |
| 186 | retry() { |
| 187 | local tries |
| 188 | if [[ $1 =~ ^[0-9]+$ ]]; then |
| 189 | tries=$1; shift |
| 190 | else |
| 191 | tries=3 |
| 192 | fi |
Petr Michalec | 262e3ad | 2017-10-06 13:41:58 +0200 | [diff] [blame] | 193 | ret=1 |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 194 | for i in $(seq 1 $tries); do |
Petr Michalec | 262e3ad | 2017-10-06 13:41:58 +0200 | [diff] [blame] | 195 | "$@" && return $? || ret=$? |
| 196 | sleep $i |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 197 | done |
Petr Michalec | 9fec8b3 | 2017-10-05 14:46:42 +0200 | [diff] [blame] | 198 | return $ret |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | function clone_reclass() { |
Petr Michalec | a361d4e | 2017-09-08 11:38:16 +0200 | [diff] [blame] | 202 | if [ ! -d ${RECLASS_ROOT}/classes ]; then |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 203 | # No reclass at all, clone from given address |
alexz | 0adc271 | 2018-02-11 17:33:52 +0100 | [diff] [blame] | 204 | # In case, non-github repo |
| 205 | _tmp_host=$(echo ${RECLASS_ADDRESS} | awk -F/ '{print $3}') |
| 206 | ssh-keyscan -T 1 -H ${_tmp_host} >> ~/.ssh/known_hosts || true |
| 207 | # But, awk is not perfect solution, so lets make double-check for github |
| 208 | ssh-keyscan -T 1 -H github.com >> ~/.ssh/known_hosts || true |
ibumarskov | f72e05e | 2017-11-29 14:37:48 +0300 | [diff] [blame] | 209 | if echo ${RECLASS_BRANCH} | egrep -q "^refs"; then |
| 210 | git clone ${RECLASS_ADDRESS} ${RECLASS_ROOT} |
| 211 | cd ${RECLASS_ROOT} |
| 212 | git fetch ${RECLASS_ADDRESS} ${RECLASS_BRANCH} && git checkout FETCH_HEAD |
| 213 | export RECLASS_REVISION=$(git rev-parse HEAD) |
| 214 | cd - |
| 215 | else |
| 216 | git clone -b ${RECLASS_BRANCH} ${RECLASS_ADDRESS} ${RECLASS_ROOT}; |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 217 | fi; |
| 218 | fi; |
Petr Michalec | 679f15b | 2017-09-18 16:16:29 +0200 | [diff] [blame] | 219 | if [ ! -d ${RECLASS_ROOT}/classes ]; then |
Petr Michalec | a361d4e | 2017-09-08 11:38:16 +0200 | [diff] [blame] | 220 | log_err "Reclass ${RECLASS_ROOT} is not fetched locally;" |
| 221 | ls -Rla ${RECLASS_ROOT} |
| 222 | exit 1 |
| 223 | fi; |
| 224 | $SUDO mkdir -p $RECLASS_ROOT/classes/service |
| 225 | $SUDO mkdir -p $RECLASS_ROOT/nodes/_generated |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | |
| 229 | ########################################## |
| 230 | # Main calls |
| 231 | |
Petr Michalec | ca2471f | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 232 | ci_config_ssh() { |
| 233 | |
| 234 | # for CI current user |
Petr Michalec | b312004 | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 235 | conf=~/.ssh/config |
| 236 | mkdir -p $(dirname $conf) |
| 237 | touch $conf |
Petr Michalec | ca2471f | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 238 | echo -e "Host *\n\tStrictHostKeyChecking $SSH_STRICTHOSTKEYCHECKING\n" | tee -a $conf >/dev/null |
Petr Michalec | b312004 | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 239 | touch ~/.ssh/known_hosts |
Petr Michalec | ca2471f | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 240 | |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 241 | if ! grep github.com ~/.ssh/known_hosts; then |
| 242 | ssh-keyscan -H github.com >> ~/.ssh/known_hosts || true |
Petr Michalec | b312004 | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 243 | ssh-keyscan -H gitlab.com >> ~/.ssh/known_hosts || true |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 244 | fi |
Petr Michalec | b312004 | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 245 | |
| 246 | # for root |
| 247 | #conf=/root/.ssh/config |
| 248 | #$SUDO mkdir -p $(dirname $conf) |
| 249 | #$SUDO touch $conf |
| 250 | #if ! $SSH_STRICTHOSTKEYCHECKING; then |
| 251 | # echo -e "Host *\n\tStrictHostKeyChecking no\n" | $SUDO tee -a $conf >/dev/null |
| 252 | #fi |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Petr Michalec | ca2471f | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 255 | # DEPRECATED |
| 256 | system_config_ssh_conf() { |
| 257 | # for backward compatibility |
| 258 | ci_config_ssh |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | system_config_salt_modules_prereq() { |
| 262 | # salt-formulas custom modules dependencies, etc: |
Petr Ruzicka | de2cd3b | 2017-12-07 14:41:20 +0100 | [diff] [blame] | 263 | $SUDO $PKGTOOL install -y apt-transport-https curl git iproute2 openssh-client python-psutil python-apt python-m2crypto python-oauth python-pip sudo &>/dev/null |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 264 | } |
| 265 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 266 | system_config_minion() { |
| 267 | log_info "System configuration salt minion" |
| 268 | } |
| 269 | |
| 270 | system_config_master() { |
| 271 | log_info "System configuration salt master" |
| 272 | |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 273 | system_config_salt_modules_prereq |
Petr Michalec | ca2471f | 2018-03-17 11:17:32 +0100 | [diff] [blame] | 274 | ci_config_ssh |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 275 | |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 276 | if ! grep '127.0.1.2.*salt' /etc/hosts; then |
| 277 | echo "127.0.1.2 salt" | $SUDO tee -a /etc/hosts >/dev/null |
| 278 | fi |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | configure_salt_master() |
| 282 | { |
| 283 | |
| 284 | echo "Configuring salt-master ..." |
| 285 | |
Petr Michalec | 4be5e5b | 2017-08-17 11:44:49 +0200 | [diff] [blame] | 286 | if [[ $RECLASS_IGNORE_CLASS_NOTFOUND =~ ^(True|true|1|yes)$ ]]; then |
Petr Michalec | 29d3ea3 | 2017-10-31 17:22:36 +0100 | [diff] [blame] | 287 | read -d '' IGNORE_CLASS_NOTFOUND <<-EOF |
| 288 | ignore_class_notfound: True |
| 289 | ignore_class_regexp: |
| 290 | - 'service.*' |
| 291 | EOF |
Petr Michalec | 4be5e5b | 2017-08-17 11:44:49 +0200 | [diff] [blame] | 292 | fi |
| 293 | |
Petr Michalec | dd1a047 | 2017-09-06 19:27:24 +0200 | [diff] [blame] | 294 | # to force alternative reclass module path |
Petr Michalec | d9d0a32 | 2017-09-06 19:38:32 +0200 | [diff] [blame] | 295 | if [ -n "$RECLASS_SOURCE_PATH" ]; then |
| 296 | RECLASS_SOURCE_PATH="reclass_source_path: ${RECLASS_SOURCE_PATH}" |
| 297 | else |
| 298 | RECLASS_SOURCE_PATH="" |
| 299 | fi |
Petr Michalec | dd1a047 | 2017-09-06 19:27:24 +0200 | [diff] [blame] | 300 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 301 | [ ! -d /etc/salt/master.d ] && mkdir -p /etc/salt/master.d |
| 302 | cat <<-EOF > /etc/salt/master.d/master.conf |
| 303 | file_roots: |
| 304 | base: |
| 305 | - /usr/share/salt-formulas/env |
| 306 | prd: |
| 307 | - /srv/salt/env/prd |
| 308 | dev: |
| 309 | - /srv/salt/env/dev |
| 310 | pillar_opts: False |
| 311 | open_mode: True |
| 312 | reclass: &reclass |
| 313 | storage_type: yaml_fs |
| 314 | inventory_base_uri: ${RECLASS_ROOT} |
Petr Michalec | 4be5e5b | 2017-08-17 11:44:49 +0200 | [diff] [blame] | 315 | ${IGNORE_CLASS_NOTFOUND} |
Petr Michalec | dd1a047 | 2017-09-06 19:27:24 +0200 | [diff] [blame] | 316 | ${RECLASS_SOURCE_PATH} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 317 | ext_pillar: |
| 318 | - reclass: *reclass |
| 319 | master_tops: |
| 320 | reclass: *reclass |
| 321 | EOF |
| 322 | |
| 323 | echo "Configuring reclass ..." |
| 324 | |
| 325 | [ ! -d /etc/reclass ] && mkdir /etc/reclass |
| 326 | cat <<-EOF > /etc/reclass/reclass-config.yml |
| 327 | storage_type: yaml_fs |
| 328 | pretty_print: True |
| 329 | output: yaml |
| 330 | inventory_base_uri: ${RECLASS_ROOT} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 331 | EOF |
| 332 | |
| 333 | clone_reclass |
| 334 | # override some envs from cluster level *.env, use with care |
| 335 | source_local_envs |
| 336 | |
| 337 | cd ${RECLASS_ROOT} |
| 338 | if [ ! -d ${RECLASS_ROOT}/classes/system/linux ]; then |
| 339 | # Possibly subrepo checkout needed |
| 340 | git submodule update --init --recursive |
| 341 | fi |
| 342 | |
Petr Michalec | 212cc6a | 2017-08-17 21:39:40 +0200 | [diff] [blame] | 343 | mkdir -vp ${RECLASS_ROOT}/nodes/_generated |
Petr Michalec | 51ece84 | 2017-09-06 20:44:15 +0200 | [diff] [blame] | 344 | rm -rvf ${RECLASS_ROOT}/nodes/_generated/* |
| 345 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 346 | CONFIG=$(find ${RECLASS_ROOT}/nodes -name ${MINION_ID}.yml| grep yml | tail -n1) |
Petr Michalec | 212cc6a | 2017-08-17 21:39:40 +0200 | [diff] [blame] | 347 | CONFIG=${CONFIG:-${RECLASS_ROOT}/nodes/_generated/${MINION_ID}.yml} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 348 | if [[ $SALT_MASTER_BOOTSTRAP_MINIMIZED =~ ^(True|true|1|yes)$ || ! -f "${CONFIG}" ]]; then |
Petr Michalec | 24b30e8 | 2017-08-21 10:59:18 +0200 | [diff] [blame] | 349 | log_warn "Salt Master node specification has not been found in model." |
| 350 | log_warn "Creating temporary cfg01 configuration for bootstrap: ${CONFIG}" |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 351 | cat <<-EOF > ${CONFIG} |
| 352 | classes: |
Petr Michalec | d81d1f5 | 2017-08-17 20:18:06 +0200 | [diff] [blame] | 353 | - cluster.${CLUSTER_NAME}.infra.config |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 354 | parameters: |
| 355 | _param: |
Petr Michalec | a7de6df | 2017-08-31 12:16:57 +0200 | [diff] [blame] | 356 | salt_master_host: ${MASTER_IP:-$MASTER_HOSTNAME} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 357 | salt_master_base_environment: $SALT_ENV |
Petr Michalec | d81d1f5 | 2017-08-17 20:18:06 +0200 | [diff] [blame] | 358 | salt_formula_branch: ${SALT_FORMULAS_BRANCH:-master} |
ibumarskov | f72e05e | 2017-11-29 14:37:48 +0300 | [diff] [blame] | 359 | reclass_data_revision: ${RECLASS_REVISION:-$RECLASS_BRANCH} |
Petr Michalec | d81d1f5 | 2017-08-17 20:18:06 +0200 | [diff] [blame] | 360 | reclass_data_repository: "$RECLASS_ADDRESS" |
Petr Michalec | a7de6df | 2017-08-31 12:16:57 +0200 | [diff] [blame] | 361 | reclass_config_master: ${MASTER_IP:-$MASTER_HOSTNAME} |
Petr Michalec | d81d1f5 | 2017-08-17 20:18:06 +0200 | [diff] [blame] | 362 | linux_system_codename: ${DISTRIB_CODENAME} |
| 363 | cluster_name: ${CLUSTER_NAME} |
| 364 | cluster_domain: ${DOMAIN:-$CLUSTER_NAME.local} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 365 | linux: |
| 366 | system: |
Petr Michalec | d81d1f5 | 2017-08-17 20:18:06 +0200 | [diff] [blame] | 367 | name: ${HOSTNAME:-cfg01} |
| 368 | domain: ${DOMAIN:-$CLUSTER_NAME.local} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 369 | # ######## |
| 370 | EOF |
| 371 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 372 | cat <<-EOF >> ${CONFIG} |
| 373 | salt: |
| 374 | master: |
| 375 | accept_policy: open_mode |
| 376 | source: |
| 377 | engine: $SALT_SOURCE |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 378 | minion: |
| 379 | source: |
| 380 | engine: $SALT_SOURCE |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 381 | # ######## |
| 382 | # vim: ft=yaml sw=2 ts=2 sts=2 |
| 383 | EOF |
| 384 | fi |
Petr Michalec | 24b30e8 | 2017-08-21 10:59:18 +0200 | [diff] [blame] | 385 | |
| 386 | log_debug "Salt Master node config yaml:" |
| 387 | log_debug "$(cat ${CONFIG})" |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | configure_salt_minion() |
| 391 | { |
| 392 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d |
| 393 | cat <<-EOF > /etc/salt/minion.d/minion.conf |
Petr Michalec | a7de6df | 2017-08-31 12:16:57 +0200 | [diff] [blame] | 394 | master: ${MASTER_IP:-$MASTER_HOSTNAME} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 395 | id: $MINION_ID |
| 396 | EOF |
| 397 | } |
| 398 | |
Petr Michalec | a6cd2bd | 2017-09-07 16:59:19 +0200 | [diff] [blame] | 399 | install_reclass() |
| 400 | { |
| 401 | VERSION=${1:-$RECLASS_VERSION} |
Petr Michalec | 372fa03 | 2017-11-15 17:36:19 +0100 | [diff] [blame] | 402 | VERSION=${VERSION:-pkg} |
Petr Michalec | 800dd07 | 2017-11-15 17:19:26 +0100 | [diff] [blame] | 403 | case ${VERSION} in |
| 404 | pkg|package) |
| 405 | which reclass || $SUDO $PKGTOOL install -y reclass |
root | b9e5d7c | 2018-03-17 12:12:44 +0000 | [diff] [blame] | 406 | which reclass-salt || { |
| 407 | if [ -e /usr/share/reclass/reclass-salt ]; then |
Petr Michalec | 6ba1c36 | 2018-03-17 15:01:51 +0100 | [diff] [blame] | 408 | ln -fs /usr/share/reclass/reclass-salt /usr/bin |
root | b9e5d7c | 2018-03-17 12:12:44 +0000 | [diff] [blame] | 409 | fi |
| 410 | } |
Petr Michalec | 800dd07 | 2017-11-15 17:19:26 +0100 | [diff] [blame] | 411 | ;; |
| 412 | *) |
Petr Michalec | 981f3cc | 2017-11-15 17:40:31 +0100 | [diff] [blame] | 413 | log_warn "Install development version of reclass" |
Petr Michalec | 1b37d3d | 2017-11-15 18:20:46 +0100 | [diff] [blame] | 414 | # Note: dev/git/pip version... |
| 415 | # It replaces all local reclass versions on system |
| 416 | # Required for reclass/git features: |
| 417 | # $SUDO $PKGTOOL install -y libffi-dev libgit2-dev || true |
Petr Michalec | 800dd07 | 2017-11-15 17:19:26 +0100 | [diff] [blame] | 418 | for s in $(python -c "import site; print(' '.join(site.getsitepackages()))"); do |
Petr Michalec | 2302083 | 2017-11-15 17:34:49 +0100 | [diff] [blame] | 419 | sudo -H pip install --install-option="--prefix=" --upgrade --force-reinstall -I \ |
Petr Michalec | 800dd07 | 2017-11-15 17:19:26 +0100 | [diff] [blame] | 420 | -t "$s" git+https://github.com/salt-formulas/reclass.git@${VERSION}; |
| 421 | done |
| 422 | ;; |
| 423 | esac |
Petr Michalec | a6cd2bd | 2017-09-07 16:59:19 +0200 | [diff] [blame] | 424 | } |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 425 | |
| 426 | install_salt_master_pkg() |
| 427 | { |
| 428 | echo -e "\nPreparing base OS repository ...\n" |
| 429 | |
| 430 | configure_pkg_repo |
| 431 | |
| 432 | echo -e "\nInstalling salt master ...\n" |
| 433 | |
| 434 | case $PLATFORM_FAMILY in |
| 435 | debian) |
| 436 | $SUDO apt-get install -y git |
alexz | 0adc271 | 2018-02-11 17:33:52 +0100 | [diff] [blame] | 437 | curl -L ${BOOTSTRAP_SALTSTACK_COM} | $SUDO sh -s -- -M ${BOOTSTRAP_SALTSTACK_OPTS} &>/dev/null || true |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 438 | ;; |
| 439 | rhel) |
| 440 | yum install -y git |
alexz | 0adc271 | 2018-02-11 17:33:52 +0100 | [diff] [blame] | 441 | curl -L ${BOOTSTRAP_SALTSTACK_COM} | $SUDO sh -s -- -M ${BOOTSTRAP_SALTSTACK_OPTS} &>/dev/null || true |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 442 | ;; |
| 443 | esac |
Jakub Josef | 0b61174 | 2018-01-09 17:02:01 +0100 | [diff] [blame] | 444 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 445 | configure_salt_master |
| 446 | |
| 447 | echo -e "\nRestarting services ...\n" |
| 448 | [ -f /etc/salt/pki/minion/minion_master.pub ] && rm -f /etc/salt/pki/minion/minion_master.pub |
| 449 | $SVCTOOL salt-master restart |
| 450 | } |
| 451 | |
| 452 | install_salt_master_pip() |
| 453 | { |
| 454 | echo -e "\nPreparing base OS repository ...\n" |
| 455 | |
| 456 | case $PLATFORM_FAMILY in |
| 457 | debian) |
| 458 | $SUDO apt-get install -y python-pip python-dev zlib1g-dev git |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 459 | ;; |
| 460 | rhel) |
| 461 | $SUDO yum install -y git |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 462 | ;; |
| 463 | esac |
| 464 | |
| 465 | echo -e "\nInstalling salt master ...\n" |
| 466 | # TODO: replace with saltstack bootstrap script |
Jakub Josef | 0b61174 | 2018-01-09 17:02:01 +0100 | [diff] [blame] | 467 | |
Petr Michalec | 88a95a2 | 2018-01-09 17:21:08 +0100 | [diff] [blame] | 468 | if [ -z ${PIP_SALT_VERSION} ] || [ "$PIP_SALT_VERSION" == "latest" ]; then |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 469 | pip install salt |
| 470 | else |
Petr Michalec | 88a95a2 | 2018-01-09 17:21:08 +0100 | [diff] [blame] | 471 | pip install salt==${PIP_SALT_VERSION} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 472 | fi |
| 473 | |
| 474 | curl -Lo /etc/init.d/salt-master https://anonscm.debian.org/cgit/pkg-salt/salt.git/plain/debian/salt-master.init && chmod 755 /etc/init.d/salt-master |
| 475 | ln -s /usr/local/bin/salt-master /usr/bin/salt-master |
| 476 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 477 | configure_salt_master |
| 478 | |
| 479 | echo -e "\nRestarting services ...\n" |
| 480 | [ -f /etc/salt/pki/minion/minion_master.pub ] && rm -f /etc/salt/pki/minion/minion_master.pub |
| 481 | $SVCTOOL salt-master restart |
| 482 | } |
| 483 | |
| 484 | |
| 485 | |
| 486 | install_salt_minion_pkg() |
| 487 | { |
| 488 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 489 | echo -e "\nInstalling salt minion ...\n" |
| 490 | |
| 491 | case $PLATFORM_FAMILY in |
| 492 | debian) |
alexz | 0adc271 | 2018-02-11 17:33:52 +0100 | [diff] [blame] | 493 | curl -L ${BOOTSTRAP_SALTSTACK_COM} | $SUDO sh -s -- ${BOOTSTRAP_SALTSTACK_OPTS} &>/dev/null || true |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 494 | ;; |
| 495 | rhel) |
alexz | 0adc271 | 2018-02-11 17:33:52 +0100 | [diff] [blame] | 496 | curl -L ${BOOTSTRAP_SALTSTACK_COM} | $SUDO sh -s -- ${BOOTSTRAP_SALTSTACK_OPTS} &>/dev/null || true |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 497 | ;; |
| 498 | esac |
| 499 | |
| 500 | |
| 501 | configure_salt_minion |
Petr Michalec | 3b7fdd8 | 2017-09-08 15:35:56 +0200 | [diff] [blame] | 502 | #$SVCTOOL salt-minion restart |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | install_salt_minion_pip() |
| 506 | { |
| 507 | echo -e "\nInstalling salt minion ...\n" |
| 508 | |
| 509 | curl -Lo /etc/init.d/salt-minion https://anonscm.debian.org/cgit/pkg-salt/salt.git/plain/debian/salt-minion.init && chmod 755 /etc/init.d/salt-minion |
| 510 | ln -s /usr/local/bin/salt-minion /usr/bin/salt-minion |
| 511 | |
| 512 | configure_salt_minion |
Petr Michalec | 3b7fdd8 | 2017-09-08 15:35:56 +0200 | [diff] [blame] | 513 | #$SVCTOOL salt-minion restart |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 514 | } |
| 515 | |
azvyagintsev | e93f837 | 2018-09-12 16:50:58 +0300 | [diff] [blame] | 516 | function install_salt_formula_pkg_all(){ |
| 517 | log_warn "Installing and configuring ALL formulas ..." |
| 518 | if ! $SUDO apt-get install -y 'salt-formula-*'; then |
| 519 | echo -e "\nInstall ALL formulas by mask 'salt-formula-*' failed.\n" |
| 520 | exit 1 |
| 521 | fi |
| 522 | for formula_service in $(ls ${FORMULAS_PATH}/reclass/service/); do |
| 523 | #Since some salt formula names contain "-" and in symlinks they should contain "_" adding replacement |
| 524 | formula_service=${formula_service//-/$'_'} |
| 525 | if [ ! -L "${RECLASS_ROOT}/classes/service/${formula_service}" ]; then |
| 526 | ln -sf ${FORMULAS_PATH}/reclass/service/${formula_service} ${RECLASS_ROOT}/classes/service/${formula_service} |
| 527 | fi |
| 528 | done |
| 529 | } |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 530 | |
| 531 | install_salt_formula_pkg() |
| 532 | { |
| 533 | configure_pkg_repo |
| 534 | |
| 535 | case $PLATFORM_FAMILY in |
| 536 | debian) |
| 537 | echo "Configuring necessary formulas ..." |
| 538 | |
| 539 | [ ! -d ${RECLASS_ROOT}/classes/service ] && mkdir -p ${RECLASS_ROOT}/classes/service |
azvyagintsev | a7a91d5 | 2018-09-13 12:58:39 +0300 | [diff] [blame] | 540 | if [[ ${EXTRA_FORMULAS_PKG_ALL} =~ ^(True|true|1|yes)$ ]]; then |
azvyagintsev | e93f837 | 2018-09-12 16:50:58 +0300 | [diff] [blame] | 541 | install_salt_formula_pkg_all |
| 542 | return |
| 543 | fi |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 544 | # Set essentials if FORMULAS_SALT_MASTER is not defined at all |
Petr Michalec | 2d75397 | 2017-11-30 16:24:37 +0100 | [diff] [blame] | 545 | [ -z ${FORMULAS_SALT_MASTER} ] && declare -a FORMULAS_SALT_MASTER=("linux" "reclass" "salt" "memcached") |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 546 | for formula_service in "${FORMULAS_SALT_MASTER[@]}"; do |
| 547 | echo -e "\nConfiguring salt formula ${formula_service} ...\n" |
| 548 | [ ! -d "${FORMULAS_PATH}/env/${formula_service}" ] && \ |
| 549 | if ! $SUDO apt-get install -y salt-formula-${formula_service}; then |
| 550 | echo -e "\nInstall salt-formula-${formula_service} failed.\n" |
| 551 | exit 1 |
| 552 | fi |
Oleksii Grudev | 691d471 | 2018-04-02 10:23:46 +0300 | [diff] [blame] | 553 | #Since some salt formula names contain "-" and in symlinks they should contain "_" adding replacement |
| 554 | formula_service=${formula_service//-/$'_'} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 555 | [ ! -L "${RECLASS_ROOT}/classes/service/${formula_service}" ] && \ |
| 556 | ln -sf ${FORMULAS_PATH}/reclass/service/${formula_service} ${RECLASS_ROOT}/classes/service/${formula_service} |
| 557 | done |
| 558 | ;; |
| 559 | rhel) |
| 560 | # TODO |
| 561 | ;; |
| 562 | esac |
| 563 | |
| 564 | [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env || echo "" |
| 565 | [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULAS_PATH}/env /srv/salt/env/prd || echo "" |
| 566 | } |
| 567 | |
| 568 | install_salt_formula_git() |
| 569 | { |
| 570 | echo "Configuring necessary formulas ..." |
| 571 | |
| 572 | [ ! -d ${RECLASS_ROOT}/classes/service ] && mkdir -p ${RECLASS_ROOT}/classes/service |
| 573 | # Set essentials if FORMULAS_SALT_MASTER is not defined at all |
Petr Michalec | 2d75397 | 2017-11-30 16:24:37 +0100 | [diff] [blame] | 574 | [ -z ${FORMULAS_SALT_MASTER} ] && declare -a FORMULAS_SALT_MASTER=("linux" "reclass" "salt" "memcached") |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 575 | for formula_service in "${FORMULAS_SALT_MASTER[@]}"; do |
| 576 | echo -e "\nConfiguring salt formula ${formula_service} ...\n" |
| 577 | _BRANCH=${FORMULAS_BRANCH} |
| 578 | [ ! -d "${FORMULAS_PATH}/env/_formulas/${formula_service}" ] && { |
| 579 | if ! git ls-remote --exit-code --heads ${FORMULAS_BASE}/salt-formula-${formula_service}.git ${_BRANCH}; then |
| 580 | # Fallback to the master branch if the branch doesn't exist for this repository |
| 581 | _BRANCH=master |
| 582 | fi |
| 583 | if ! git clone ${FORMULAS_BASE}/salt-formula-${formula_service}.git ${FORMULAS_PATH}/env/_formulas/${formula_service} -b ${_BRANCH}; then |
| 584 | echo -e "\nCloning of ${FORMULAS_BASE}/salt-formula-${formula_service}.git failed.\n" |
| 585 | exit 1 |
| 586 | fi |
| 587 | } || { |
| 588 | cd ${FORMULAS_PATH}/env/_formulas/${formula_service}; |
| 589 | git fetch origin/${_BRANCH} || git fetch --all |
| 590 | git checkout ${_BRANCH} && git pull || git pull; |
| 591 | cd - |
| 592 | } |
| 593 | [ ! -L "/usr/share/salt-formulas/env/${formula_service}" ] && \ |
| 594 | ln -sf ${FORMULAS_PATH}/env/_formulas/${formula_service}/${formula_service} /usr/share/salt-formulas/env/${formula_service} |
| 595 | [ ! -L "${RECLASS_ROOT}/classes/service/${formula_service}" ] && \ |
| 596 | ln -sf ${FORMULAS_PATH}/env/_formulas/${formula_service}/metadata/service ${RECLASS_ROOT}/classes/service/${formula_service} |
| 597 | done |
| 598 | |
| 599 | [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env || echo "" |
| 600 | [ ! -L /srv/salt/env/dev ] && ln -s /usr/share/salt-formulas/env /srv/salt/env/dev || echo "" |
| 601 | } |
| 602 | |
Petr Michalec | e9c8452 | 2017-12-13 17:14:08 +0100 | [diff] [blame] | 603 | saltservice_stop() { |
Petr Michalec | dd646db | 2017-12-18 15:56:18 +0100 | [diff] [blame] | 604 | set +e |
Petr Michalec | e9c8452 | 2017-12-13 17:14:08 +0100 | [diff] [blame] | 605 | $SUDO service salt-minion stop |
| 606 | $SUDO service salt-master stop |
| 607 | sleep ${SALT_STOPSTART_WAIT:-30} |
Petr Michalec | 7822efe | 2017-12-15 16:19:32 +0100 | [diff] [blame] | 608 | ${SUDO} pkill -9 salt-master && ${SUDO} rm -rf /var/run/salt/master/* || true |
Petr Michalec | e9c8452 | 2017-12-13 17:14:08 +0100 | [diff] [blame] | 609 | ${SUDO} pkill -9 salt-minion |
| 610 | } |
| 611 | saltservice_start() { |
Petr Michalec | dd646db | 2017-12-18 15:56:18 +0100 | [diff] [blame] | 612 | set +e |
Petr Michalec | e9c8452 | 2017-12-13 17:14:08 +0100 | [diff] [blame] | 613 | $SUDO service salt-master start |
| 614 | $SUDO service salt-minion start |
| 615 | sleep ${SALT_STOPSTART_WAIT:-30} |
| 616 | } |
| 617 | |
| 618 | saltservice_restart() { |
Petr Michalec | dd646db | 2017-12-18 15:56:18 +0100 | [diff] [blame] | 619 | set +e |
Petr Michalec | e9c8452 | 2017-12-13 17:14:08 +0100 | [diff] [blame] | 620 | saltservice_stop |
| 621 | saltservice_start |
| 622 | } |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 623 | |
| 624 | saltmaster_bootstrap() { |
| 625 | |
| 626 | log_info "Salt master setup" |
| 627 | test -n "$MASTER_HOSTNAME" || exit 1 |
| 628 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 629 | # override some envs from cluster level *.env, use with care |
| 630 | source_local_envs |
| 631 | |
Petr Michalec | e9c8452 | 2017-12-13 17:14:08 +0100 | [diff] [blame] | 632 | saltservice_stop |
| 633 | |
| 634 | clone_reclass |
| 635 | |
projoke | 3c30e7d | 2017-10-19 17:15:40 +0800 | [diff] [blame] | 636 | SCRIPTS=$(dirname $0) |
Petr Michalec | e9c8452 | 2017-12-13 17:14:08 +0100 | [diff] [blame] | 637 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 638 | test -e ${SCRIPTS}/.salt-master-setup.sh.passed || { |
Adam Tengler | 035f24f | 2017-09-11 19:29:31 +0200 | [diff] [blame] | 639 | export MASTER_IP=${MASTER_IP:-127.0.0.1} |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 640 | export MINION_ID=${MASTER_HOSTNAME} |
| 641 | if ! [[ $DEBUG =~ ^(True|true|1|yes)$ ]]; then |
| 642 | SALT_MASTER_SETUP_OUTPUT='/dev/stdout' |
| 643 | fi |
| 644 | # call local "setup() master" |
| 645 | #if ! $SUDO ${SCRIPTS}/salt-master-setup.sh master &> ${SALT_MASTER_SETUP_OUTPUT:-/tmp/salt-master-setup.log}; then |
| 646 | if ! setup master; then |
| 647 | #cat /tmp/salt-master-setup.log |
| 648 | log_err "salt master setup() failed." |
| 649 | exit 1 |
| 650 | else |
| 651 | $SUDO touch ${SCRIPTS}/.salt-master-setup.sh.passed |
| 652 | fi |
| 653 | } |
| 654 | |
Petr Michalec | 981f3cc | 2017-11-15 17:40:31 +0100 | [diff] [blame] | 655 | log_info "Install reclass" |
| 656 | install_reclass ${RECLASS_VERSION/dev*/develop} |
Petr Michalec | a6cd2bd | 2017-09-07 16:59:19 +0200 | [diff] [blame] | 657 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 658 | log_info "Re/starting salt services" |
Petr Michalec | e9c8452 | 2017-12-13 17:14:08 +0100 | [diff] [blame] | 659 | saltservice_restart |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | # Init salt master |
| 663 | saltmaster_init() { |
| 664 | |
| 665 | log_info "Runing saltmaster states" |
| 666 | test -n "$MASTER_HOSTNAME" || exit 1 |
| 667 | |
| 668 | set -e |
| 669 | $SUDO salt-call saltutil.sync_all >/dev/null |
| 670 | |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 671 | # workarond isolated and not fully bootstraped environments |
Petr Michalec | 2801acb | 2017-10-31 15:00:15 +0100 | [diff] [blame] | 672 | if [[ $RECLASS_IGNORE_CLASS_NOTFOUND =~ ^(True|true|1|yes)$ ]]; then |
Petr Michalec | 54ee408 | 2017-11-30 17:02:17 +0100 | [diff] [blame] | 673 | SALT_MASTER_PILLAR='"salt":{"master":{"pillar":{"reclass":{"ignore_class_notfound": '${RECLASS_IGNORE_CLASS_NOTFOUND:-False}', "ignore_class_regexp": ["service.*"]}}}},' |
Petr Michalec | 2801acb | 2017-10-31 15:00:15 +0100 | [diff] [blame] | 674 | fi |
Petr Michalec | 8ce8a65 | 2017-11-30 15:39:20 +0100 | [diff] [blame] | 675 | PILLAR='{'${SALT_MASTER_PILLAR}' "reclass":{"storage":{"data_source":{"engine":"local"}}} }' |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 676 | |
Petr Michalec | 8b92d55 | 2017-11-29 12:28:50 +0100 | [diff] [blame] | 677 | log_info "State: salt.master.env,salt.master.pillar" |
Petr Michalec | 54ee408 | 2017-11-30 17:02:17 +0100 | [diff] [blame] | 678 | if ! $SUDO salt-call ${SALT_OPTS} state.apply salt.master.env,salt.master.pillar pillar="$PILLAR"; then |
Petr Michalec | 85ef7ad | 2017-11-30 15:21:19 +0100 | [diff] [blame] | 679 | log_err "State \`salt.master.env,salt.master.pillar pillar=$PILLAR\` failed, keep your eyes wide open!" |
azvyagintsev | e3f6f40 | 2018-08-23 17:21:49 +0300 | [diff] [blame] | 680 | if [[ $SA_IGNORE_ERROR_SALT_MASTER_ENV =~ ^(False|false|0|no)$ ]]; then |
| 681 | exit 1 |
| 682 | fi |
| 683 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 684 | fi |
| 685 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 686 | # Revert temporary SaltMaster minimal configuration, if any |
| 687 | pushd $RECLASS_ROOT |
| 688 | if [ $(git diff --name-only nodes | sort | uniq | wc -l) -ge 1 ]; then |
Petr Michalec | 87778fc | 2017-11-02 10:13:25 +0100 | [diff] [blame] | 689 | PILLAR='{"reclass":{"storage":{"data_source":{"engine":"local"}}} }' |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 690 | git status || true |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 691 | log_warn "Locally modified $RECLASS_ROOT/nodes found. (Possibly salt-master minimized setup from bootstrap.sh call)" |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 692 | log_info "Checkout HEAD state of $RECLASS_ROOT/nodes/*." |
| 693 | git checkout -- $RECLASS_ROOT/nodes || true |
| 694 | log_info "Re-Run states: salt.master.env and salt.master.pillar according the HEAD state." |
Petr Michalec | 7edf832 | 2017-11-30 12:01:09 +0100 | [diff] [blame] | 695 | log_info "State: salt.master.env,salt.master.pillar" |
Petr Michalec | 54ee408 | 2017-11-30 17:02:17 +0100 | [diff] [blame] | 696 | if ! $SUDO salt-call ${SALT_OPTS} state.apply salt.master.env,salt.master.pillar pillar="$PILLAR"; then |
Petr Michalec | 85ef7ad | 2017-11-30 15:21:19 +0100 | [diff] [blame] | 697 | log_err "State \`salt.master.env,salt.master.pillar pillar=$PILLAR\` failed, keep your eyes wide open!" |
azvyagintsev | e3f6f40 | 2018-08-23 17:21:49 +0300 | [diff] [blame] | 698 | if [[ $SA_IGNORE_ERROR_SALT_MASTER_ENV =~ ^(False|false|0|no)$ ]]; then |
| 699 | exit 1 |
| 700 | fi |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 701 | fi |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 702 | fi |
| 703 | popd |
| 704 | |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 705 | # finally re-configure salt master conf, ie: may remove ignore_class_notfound option |
| 706 | log_info "State: salt.master.service" |
Jakub Josef | 3256341 | 2018-01-17 17:55:05 +0100 | [diff] [blame] | 707 | # ensure salt master is started |
| 708 | saltservice_start |
Petr Michalec | 9fec8b3 | 2017-10-05 14:46:42 +0200 | [diff] [blame] | 709 | retry ${SALT_STATE_RETRY} $SUDO salt-call ${SALT_OPTS} state.apply salt.master.service || true |
Petr Michalec | 4f04377 | 2017-12-19 15:40:54 +0100 | [diff] [blame] | 710 | saltservice_start |
Petr Michalec | da01420 | 2017-08-18 11:26:07 +0200 | [diff] [blame] | 711 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 712 | log_info "State: salt.master.storage.node" |
| 713 | set +e |
Petr Michalec | 7edf832 | 2017-11-30 12:01:09 +0100 | [diff] [blame] | 714 | # TODO: PLACEHOLDER TO TRIGGER NODE GENERATION THROUG SALT REACT. |
| 715 | # FIXME: PLACEHOLDER TO TRIGGER NODE GENERATION THROUG SALT REACT. |
Petr Michalec | 9fec8b3 | 2017-10-05 14:46:42 +0200 | [diff] [blame] | 716 | retry ${SALT_STATE_RETRY} $SUDO salt-call ${SALT_OPTS} state.apply reclass.storage.node |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 717 | ret=$? |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 718 | |
Petr Michalec | dd646db | 2017-12-18 15:56:18 +0100 | [diff] [blame] | 719 | set -e |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 720 | if [[ $ret -eq 2 ]]; then |
| 721 | log_err "State reclass.storage.node failed with exit code 2 but continuing." |
| 722 | elif [[ $ret -ne 0 ]]; then |
| 723 | log_err "State reclass.storage.node failed with exit code $ret" |
| 724 | exit 1 |
| 725 | fi |
| 726 | |
Petr Michalec | dd646db | 2017-12-18 15:56:18 +0100 | [diff] [blame] | 727 | set +e |
| 728 | log_info "Updating minion.conf -> master: localhost" |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 729 | $SUDO sed -i 's/^master:.*/master: localhost/' /etc/salt/minion.d/minion.conf |
Petr Michalec | dd646db | 2017-12-18 15:56:18 +0100 | [diff] [blame] | 730 | |
| 731 | log_info "Re/starting salt services" # in order to load new deployed configuration from model |
Petr Michalec | e9c8452 | 2017-12-13 17:14:08 +0100 | [diff] [blame] | 732 | saltservice_restart |
Petr Michalec | dd646db | 2017-12-18 15:56:18 +0100 | [diff] [blame] | 733 | |
| 734 | log_info "Salt Util sync all" |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 735 | $SUDO salt-call ${SALT_OPTS} saltutil.sync_all >/dev/null |
| 736 | |
| 737 | verify_salt_master |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 738 | |
| 739 | } |
| 740 | |
Petr Michalec | 71e3268 | 2018-03-22 08:34:34 +0100 | [diff] [blame] | 741 | ## CI Workarounds |
| 742 | |
| 743 | function mockup_node_registration() { |
| 744 | |
| 745 | # for dynamic nodes registrations (require github.com/salt-formulas/salt-formula-reclass) |
| 746 | |
| 747 | source /etc/os-release |
| 748 | os_codename=$VERSION_CODENAME |
| 749 | domain=$(hostname -d) |
| 750 | master_ip=$(hostname -I | awk '{print $1}') |
| 751 | fake_ip_preffix=$(echo $master_ip | awk -F. '{print $1"."$2}') |
| 752 | fake_ip_base=10 |
| 753 | |
| 754 | # SHOULD BE ALREADY RUN AS A PART OF BOOTSTRAP |
| 755 | # sync, in order to load custom modules |
| 756 | #salt-call saltutil.sync_all |
| 757 | |
| 758 | # SHOULD BE ALREADY RUN AS A PART OF BOOTSTRAP |
| 759 | #PILLAR='{"reclass":{"storage":{"data_source":{"engine":"local"}}} }' |
| 760 | #salt-call state.apply reclass.storage.node pillar="$PILLAR" > /dev/null 2>/dev/null || true |
| 761 | |
| 762 | # rotate over dynamic hosts |
| 763 | for host_idx in {01..02};do |
| 764 | for host in `salt-call pillar.items reclass:storage |grep '<<node_hostname>>' | awk -F_ '{print $NF}' | sed 's/[0-9]*//g' | egrep -v cfg | sort -u`; do |
| 765 | hostname=${host}${host_idx} |
| 766 | fake_ip_base=$(($fake_ip_base + 1)) |
| 767 | |
| 768 | node_network01_ip="$fake_ip_preffix.11.$fake_ip_base" |
| 769 | node_network02_ip="$fake_ip_preffix.12.$fake_ip_base" |
| 770 | node_network03_ip="$fake_ip_preffix.13.$fake_ip_base" |
| 771 | node_network04_ip="$fake_ip_preffix.14.$fake_ip_base" |
| 772 | node_network05_ip="$fake_ip_preffix.15.$fake_ip_base" |
| 773 | node_network01_iface=$(ls /sys/class/net/ | grep -v lo | sort | head -n1) |
| 774 | node_network02_iface="eth1" |
| 775 | node_network03_iface="eth2" |
| 776 | node_network04_iface="eth3" |
| 777 | node_network05_iface="eth4" |
| 778 | |
| 779 | declare -A vars |
| 780 | vars=( |
| 781 | ["node_master_ip"]= |
| 782 | ["node_os"]=${os_codename} |
| 783 | ["node_deploy_ip"]=${node_network01_ip} |
| 784 | ["node_deploy_iface"]=${node_network01_iface} |
| 785 | ["node_control_ip"]=${node_network02_ip} |
| 786 | ["node_control_iface"]=${node_network02_iface} |
| 787 | ["node_tenant_ip"]=${node_network03_ip} |
| 788 | ["node_tenant_iface"]=${node_network03_iface} |
| 789 | ["node_external_ip"]=${node_network04_ip} |
| 790 | ["node_external_iface"]=${node_network04_iface} |
| 791 | ["node_baremetal_ip"]=${node_network05_ip} |
| 792 | ["node_baremetal_iface"]=${node_network05_iface} |
| 793 | ["node_domain"]=$domain |
| 794 | ["node_cluster"]=$(hostname -d |awk -F. '{print $1}') |
| 795 | ["node_hostname"]=$hostname |
| 796 | ) |
| 797 | |
| 798 | data=""; i=0 |
| 799 | for key in "${!vars[@]}"; do |
| 800 | data+="\"${key}\": \"${vars[${key}]}\"" |
| 801 | i=$(($i+1)) |
| 802 | if [ $i -lt ${#vars[@]} ]; then |
| 803 | data+=", " |
| 804 | fi |
| 805 | done |
| 806 | echo "Classifying node $hostname" |
| 807 | NODECR='"node_name": "'${hostname}.${domain}'", "node_data": {'$data'}' |
| 808 | PILLAR='{'${NODECR}', "reclass":{"storage":{"data_source":{"engine":"local"}}} }' |
| 809 | salt-call state.apply reclass.reactor_sls.node_register pillar="$PILLAR" #-l info |
| 810 | #salt-call event.send "reclass/minion/classify" "{$data}" |
| 811 | done |
| 812 | done |
| 813 | |
| 814 | } |
| 815 | |
| 816 | ## VERIFY |
| 817 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 818 | |
| 819 | function verify_salt_master() { |
| 820 | set -e |
| 821 | |
| 822 | log_info "Verify Salt master" |
| 823 | test -n "$MASTER_HOSTNAME" || exit 1 |
| 824 | |
| 825 | if [[ $VERIFY_SALT_CALL =~ ^(True|true|1|yes)$ ]]; then |
Petr Michalec | a514134 | 2017-08-16 12:55:20 +0200 | [diff] [blame] | 826 | $SUDO salt-call ${SALT_OPTS} --id=${MASTER_HOSTNAME} reclass.validate_yaml > /tmp/${MASTER_HOSTNAME}.reclass.validate_yaml |
| 827 | $SUDO salt-call ${SALT_OPTS} --id=${MASTER_HOSTNAME} reclass.validate_pillar > /tmp/${MASTER_HOSTNAME}.reclass.validate_pillar |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 828 | $SUDO salt-call ${SALT_OPTS} --id=${MASTER_HOSTNAME} grains.item roles > /tmp/${MASTER_HOSTNAME}.grains.item.roles |
| 829 | $SUDO salt-call ${SALT_OPTS} --id=${MASTER_HOSTNAME} state.show_lowstate > /tmp/${MASTER_HOSTNAME}.state.show_state |
| 830 | $SUDO salt-call --no-color grains.items |
| 831 | $SUDO salt-call --no-color pillar.data |
| 832 | fi |
Petr Michalec | a514134 | 2017-08-16 12:55:20 +0200 | [diff] [blame] | 833 | # TODO: REMOVE reclass --nodeinfo section / run only on debug - as the only required is reclass.validate_* |
Petr Michalec | 6e40efc | 2018-03-22 09:47:47 +0100 | [diff] [blame] | 834 | if ! $SUDO python -m reclass.cli --nodeinfo ${MASTER_HOSTNAME} > /tmp/${MASTER_HOSTNAME}.reclass.nodeinfo; then |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 835 | log_err "For more details see full log /tmp/${MASTER_HOSTNAME}.reclass.nodeinfo" |
| 836 | exit 1 |
| 837 | fi |
Petr Michalec | 7edf832 | 2017-11-30 12:01:09 +0100 | [diff] [blame] | 838 | set +e |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | function verify_salt_minion() { |
| 842 | set -e |
| 843 | node=$1 |
| 844 | log_info "Verifying ${node}" |
| 845 | if [[ $VERIFY_SALT_CALL =~ ^(True|true|1|yes)$ ]]; then |
| 846 | $SUDO salt-call ${SALT_OPTS} --id=${node} grains.item roles > /tmp/${node}.grains.item.roles |
| 847 | $SUDO salt-call ${SALT_OPTS} --id=${node} state.show_lowstate > /tmp/${node}.state.show_lowstate |
| 848 | fi |
Petr Michalec | 6e40efc | 2018-03-22 09:47:47 +0100 | [diff] [blame] | 849 | if ! $SUDO python -m reclass.cli --nodeinfo ${node} > /tmp/${node}.reclass.nodeinfo; then |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 850 | log_err "For more details see full log /tmp/${node}.reclass.nodeinfo" |
| 851 | if [[ ${BREAK_ON_VERIFICATION_ERROR:-yes} =~ ^(True|true|1|yes)$ ]]; then |
| 852 | exit 1 |
| 853 | fi |
| 854 | fi |
Petr Michalec | 7edf832 | 2017-11-30 12:01:09 +0100 | [diff] [blame] | 855 | set +e |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | function verify_salt_minions() { |
| 859 | #set -e |
Petr Michalec | 679f15b | 2017-09-18 16:16:29 +0200 | [diff] [blame] | 860 | NODES=$(find $RECLASS_ROOT/nodes/_generated/ -name "*.yml" | grep -v "cfg") |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 861 | log_info "Verifying minions: $(echo ${NODES}|xargs)" |
| 862 | |
| 863 | # Parallel |
| 864 | #echo $NODES | parallel --no-notice -j 2 --halt 2 "verify_salt_minion \$(basename {} .yml) > {}.pillar_verify" |
| 865 | #ls -lrta *.pillar_verify | tail -n 1 | xargs -n1 tail -n30 |
| 866 | |
| 867 | function filterFails() { |
| 868 | grep -v '/grains' | tee -a $1 | tail -n20 |
| 869 | } |
| 870 | |
| 871 | log_info "Verify nodes" |
| 872 | passed=0 |
| 873 | for node in ${NODES}; do |
| 874 | node=$(basename $node .yml) |
| 875 | |
| 876 | # filter first in cluster.. ctl-01, mon-01, etc.. |
| 877 | if [[ "${node//.*}" =~ 01 || "${node//.*}" =~ 02 ]] ;then |
| 878 | verify_salt_minion ${node} || continue |
| 879 | else |
| 880 | echo Skipped $node. |
| 881 | fi |
| 882 | passed=$(($passed+1)) |
| 883 | done |
| 884 | # fail on failures |
| 885 | total=$(echo $NODES | xargs --no-run-if-empty -n1 echo |wc -l) |
| 886 | test ! $passed -lt $total || log_err "Results: $passed of $total passed." |
| 887 | test ! $passed -lt $total || { |
| 888 | tail -n50 /tmp/*.pillar_verify |
| 889 | return 1 |
| 890 | } |
Petr Michalec | 7edf832 | 2017-11-30 12:01:09 +0100 | [diff] [blame] | 891 | #set +e |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | |
| 895 | |
| 896 | ########################################## |
| 897 | # To install salt master/minon |
| 898 | |
| 899 | function install() { |
| 900 | setup $@ |
| 901 | } |
| 902 | |
| 903 | function setup() { |
| 904 | # CLI |
| 905 | while [ x"$1" != x"" ]; do |
| 906 | which curl &>/dev/null || $PKGTOOL -y install curl &>/dev/null |
| 907 | |
| 908 | case $1 in |
| 909 | master ) |
| 910 | install_salt_master_$SALT_SOURCE |
| 911 | install_salt_minion_$SALT_SOURCE |
| 912 | install_salt_formula_$FORMULAS_SOURCE |
| 913 | ;; |
| 914 | minion ) |
| 915 | install_salt_minion_$SALT_SOURCE |
| 916 | ;; |
| 917 | esac |
| 918 | shift |
| 919 | done |
| 920 | echo DONE |
| 921 | } |
| 922 | |
| 923 | function bootstrap() { |
| 924 | log_info "Bootstrap & verification of SaltMaster and configured minions." |
| 925 | trap _atexit INT TERM EXIT |
| 926 | |
| 927 | system_config_master |
| 928 | saltmaster_bootstrap &&\ |
Petr Michalec | 58575b9 | 2017-08-20 10:42:25 +0200 | [diff] [blame] | 929 | saltmaster_init #&&\ |
Petr Michalec | a514134 | 2017-08-16 12:55:20 +0200 | [diff] [blame] | 930 | #verify_salt_minions |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | function default() { |
| 934 | bootstrap $@ |
| 935 | } |
| 936 | |
| 937 | |
| 938 | ########################################## |
azvyagintsev | e93f837 | 2018-09-12 16:50:58 +0300 | [diff] [blame] | 939 | log_info "Running version: ${__ScriptVersion}" |
| 940 | log_info "Command line: '${__ScriptFullName} ${__ScriptArgs}'" |
| 941 | |
Petr Michalec | 1ed1b3c | 2017-08-08 19:19:01 +0200 | [diff] [blame] | 942 | [[ "$0" != "$BASH_SOURCE" ]] || { |
| 943 | # unless file is being sourced |
| 944 | default $@ |
| 945 | } |