Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 1 | #cloud-config |
Ivan Berezovskiy | 39fa656 | 2018-10-09 12:58:55 +0400 | [diff] [blame] | 2 | output: |
| 3 | all: '| tee -a /var/log/cloud-init-output.log /dev/tty0' |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 4 | write_files: |
| 5 | - owner: root:root |
| 6 | path: /etc/cloud/master_environment |
| 7 | permissions: '0644' |
| 8 | content: | |
Dennis Dmitriev | 8fa33f9 | 2018-10-10 01:13:48 +0300 | [diff] [blame] | 9 | [ -f /etc/cloud/master_environment_override ] && . /etc/cloud/master_environment_override |
| 10 | export SALT_MASTER_DEPLOY_IP=${SALT_MASTER_DEPLOY_IP:-"172.16.164.15"} |
| 11 | export SALT_MASTER_MINION_ID=${SALT_MASTER_MINION_ID:-"cfg01.deploy-name.local"} |
azvyagintsev | 829bfd8 | 2018-12-19 12:58:17 +0200 | [diff] [blame] | 12 | |
Dennis Dmitriev | 8fa33f9 | 2018-10-10 01:13:48 +0300 | [diff] [blame] | 13 | export http_proxy=${http_proxy:-""} |
| 14 | export https_proxy=${https_proxy:-""} |
azvyagintsev | 829bfd8 | 2018-12-19 12:58:17 +0200 | [diff] [blame] | 15 | |
| 16 | export MCP_VERSION=${MCP_VERSION:-"stable"} |
| 17 | |
Dennis Dmitriev | 8fa33f9 | 2018-10-10 01:13:48 +0300 | [diff] [blame] | 18 | export PIPELINES_FROM_ISO=${PIPELINES_FROM_ISO:-"true"} |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 19 | export MK_PIPELINES_URL=${MK_PIPELINES_URL:-"https://gerrit.mcp.mirantis.com/mk/mk-pipelines.git"} |
| 20 | export PIPELINE_LIB_URL=${PIPELINE_LIB_URL:-"https://gerrit.mcp.mirantis.com/mcp-ci/pipeline-library.git"} |
azvyagintsev | 829bfd8 | 2018-12-19 12:58:17 +0200 | [diff] [blame] | 21 | |
| 22 | export MCP_SALT_REPO_URL=${MCP_SALT_REPO_URL:-"http://mirror.mirantis.com/"} |
| 23 | export MCP_SALT_REPO=${MCP_SALT_REPO:-"deb [arch=amd64] $MCP_SALT_REPO_URL/$MCP_VERSION/salt-formulas/xenial xenial main"} |
azvyagintsev | aa0c484 | 2019-05-16 12:30:25 +0300 | [diff] [blame] | 24 | |
| 25 | export ENABLE_MCP_SALT_REPO_UPDATES=${ENABLE_MCP_SALT_REPO_UPDATES:-"true"} |
azvyagintsev | 829bfd8 | 2018-12-19 12:58:17 +0200 | [diff] [blame] | 26 | export MCP_SALT_REPO_UPDATES=${MCP_SALT_REPO_UPDATES:-"deb [arch=amd64] $MCP_SALT_REPO_URL/update/$MCP_VERSION/salt-formulas/xenial xenial main"} |
| 27 | export MCP_SALT_REPO_KEY=${MCP_SALT_REPO_KEY:-"${MCP_SALT_REPO_URL}/${MCP_VERSION}/salt-formulas/xenial/archive-salt-formulas.key"} |
| 28 | |
Dennis Dmitriev | 8fa33f9 | 2018-10-10 01:13:48 +0300 | [diff] [blame] | 29 | export FORMULAS=${FORMULAS:-"salt-formula-*"} |
azvyagintsev | 829bfd8 | 2018-12-19 12:58:17 +0200 | [diff] [blame] | 30 | export SALT_OPTS=${SALT_OPTS:-"-l debug -t 30 --retcode-passthrough --no-color"} |
Dennis Dmitriev | 8fa33f9 | 2018-10-10 01:13:48 +0300 | [diff] [blame] | 31 | export CFG_BOOTSTRAP_DRIVE_URL=${CFG_BOOTSTRAP_DRIVE_URL:-""} |
azvyagintsev | 829bfd8 | 2018-12-19 12:58:17 +0200 | [diff] [blame] | 32 | |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 33 | master_config: |
| 34 | - &master_config | |
| 35 | function _post_maas_cfg() { |
azvyagintsev | a126bf1 | 2019-05-16 12:55:35 +0300 | [diff] [blame^] | 36 | # In newer maas version, apache2 disabled, so API avaible on direct service port only |
| 37 | if [[ ! $(systemctl is-active --quiet apache2) ]] ; then |
| 38 | sed -i 's/API_SERVER=.*/API_SERVER=localhost:5240/g' /var/lib/maas/.maas_login.sh |
| 39 | fi |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 40 | source /var/lib/maas/.maas_login.sh |
| 41 | # disable backports for maas enlist pkg repo. Those operation enforce maas |
| 42 | # to re-create sources.list and drop [source] fetch-definition from it. |
| 43 | main_arch_id=$(maas ${PROFILE} package-repositories read | jq -r ".[] | select(.name==\"main_archive\") | .id") |
| 44 | maas ${PROFILE} package-repository update ${main_arch_id} "disabled_pockets=backports" || true |
| 45 | maas ${PROFILE} package-repository update ${main_arch_id} "disabled_components=multiverse" || true |
| 46 | maas ${PROFILE} package-repository update ${main_arch_id} "arches=amd64" || true |
| 47 | # Remove stale notifications, which appear during sources configuration. |
| 48 | for i in $(maas ${PROFILE} notifications read | jq ".[]| .id"); do |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 49 | maas ${PROFILE} notification delete ${i} || true |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 50 | done |
| 51 | } |
| 52 | |
| 53 | function process_formulas(){ |
| 54 | local RECLASS_ROOT=${RECLASS_ROOT:-/srv/salt/reclass/} |
| 55 | local FORMULAS_PATH=${FORMULAS_PATH:-/usr/share/salt-formulas} |
| 56 | |
azvyagintsev | 829bfd8 | 2018-12-19 12:58:17 +0200 | [diff] [blame] | 57 | curl -s ${MCP_SALT_REPO_KEY} | apt-key add - |
| 58 | echo "${MCP_SALT_REPO}" > /etc/apt/sources.list.d/mcp_salt.list |
azvyagintsev | aa0c484 | 2019-05-16 12:30:25 +0300 | [diff] [blame] | 59 | if [[ "${ENABLE_MCP_SALT_REPO_UPDATES}" == "true" ]] ; then |
| 60 | echo "${MCP_SALT_REPO_UPDATES}" >> /etc/apt/sources.list.d/mcp_salt.list |
| 61 | fi |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 62 | apt update && apt install -y "${FORMULAS}" |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 63 | |
| 64 | [ ! -d ${RECLASS_ROOT}/classes/service ] && mkdir -p ${RECLASS_ROOT}/classes/service |
| 65 | for formula_service in $(ls /usr/share/salt-formulas/reclass/service/); do |
| 66 | #Since some salt formula names contain "-" and in symlinks they should contain "_" adding replacement |
| 67 | formula_service=${formula_service//-/$"_"} |
| 68 | if [ ! -L "${RECLASS_ROOT}/classes/service/${formula_service}" ]; then |
| 69 | ln -sf ${FORMULAS_PATH}/reclass/service/${formula_service} ${RECLASS_ROOT}/classes/service/${formula_service} |
| 70 | fi |
| 71 | done |
| 72 | } |
| 73 | |
| 74 | function enable_services(){ |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 75 | local services="salt-api salt-master salt-minion" |
| 76 | if [ ! -f /opt/postgresql_in_docker ]; then |
| 77 | local services="${services} postgresql.service" |
| 78 | fi |
| 79 | for s in ${services} ; do |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 80 | systemctl enable ${s} || true |
| 81 | systemctl restart ${s} || true |
| 82 | done |
| 83 | } |
| 84 | |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 85 | function process_maas(){ |
Ivan Berezovskiy | a469140 | 2019-03-12 14:18:01 +0400 | [diff] [blame] | 86 | maas_cluster_enabled=$(salt-call --out=newline_values_only pillar.get maas:cluster:enabled | tr "[:upper:]" "[:lower:]" ) |
| 87 | _region=$(salt-call --out=newline_values_only pillar.get maas:region:enabled | tr "[:upper:]" "[:lower:]" ) |
Stanislav Riazanov | 450ceaa | 2018-12-18 20:17:07 +0400 | [diff] [blame] | 88 | if ([ -f /opt/postgresql_in_docker ] && ([[ "${maas_cluster_enabled}" == "true" ]] || [[ "${_region}" == "true" ]])); then |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 89 | systemctl disable postgresql.service |
| 90 | wait_for_postgresql |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 91 | salt-call ${SALT_OPTS} state.apply postgresql.client |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 92 | else |
Ivan Berezovskiy | a469140 | 2019-03-12 14:18:01 +0400 | [diff] [blame] | 93 | postgres_enabled=$(salt-call --out=newline_values_only pillar.get postgresql:server:enabled | tr "[:upper:]" "[:lower:]") |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 94 | if [[ "${postgres_enabled}" == "true" ]]; then |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 95 | salt-call ${SALT_OPTS} state.apply postgresql.server |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 96 | fi |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 97 | fi |
| 98 | |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 99 | if [[ "${maas_cluster_enabled}" == "true" ]]; then |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 100 | salt-call ${SALT_OPTS} state.apply maas.cluster |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 101 | else |
| 102 | echo "WARNING: maas.cluster skipped!" |
| 103 | fi |
| 104 | if [[ "$_region" == "true" ]]; then |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 105 | salt-call ${SALT_OPTS} state.apply maas.region |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 106 | else |
| 107 | echo "WARNING: maas.region skipped!" |
| 108 | fi |
| 109 | # Do not move it under first cluster-only check! |
| 110 | if [[ "${maas_cluster_enabled}" == "true" ]]; then |
| 111 | _post_maas_cfg |
| 112 | fi |
| 113 | } |
| 114 | |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 115 | function wait_for_postgresql() { |
| 116 | salt_string="salt-call --out=text pillar.get postgresql:client:server:server01:admin" |
| 117 | pg_port=$(${salt_string}:port | awk '{print $2}') |
| 118 | pg_host=$(${salt_string}:host | awk '{print $2}') |
| 119 | wait_time=0 |
| 120 | until [[ $(/usr/bin/pg_isready -h ${pg_host} -p ${pg_port} | awk '{ print $3 }' ) == 'accepting' ]] || [ $wait_time -eq 20 ]; |
| 121 | do |
| 122 | echo "Waiting for postgres at: ${pg_host}:${pg_port}" |
| 123 | sleep $(( wait_time++ )); |
| 124 | done |
| 125 | } |
| 126 | |
Ivan Berezovskiy | 11d374b | 2018-11-26 18:00:23 +0400 | [diff] [blame] | 127 | function wait_for_jenkins() { |
| 128 | # Wait for jenkins to be functional |
Ivan Berezovskiy | a469140 | 2019-03-12 14:18:01 +0400 | [diff] [blame] | 129 | j_host=$(salt-call --out=newline_values_only pillar.get jenkins:client:master:host) |
| 130 | j_host=${j_host:-"localhost"} |
| 131 | j_port=$(salt-call --out=newline_values_only pillar.get jenkins:client:master:port) |
| 132 | j_port=${j_port:-"8081"} |
| 133 | j_prefix=$(salt-call --out=newline_values_only pillar.get jenkins:client:master:url_prefix) |
| 134 | j_prefix=${j_prefix:-""} |
Ivan Berezovskiy | 11d374b | 2018-11-26 18:00:23 +0400 | [diff] [blame] | 135 | wait_time=0 |
Ivan Berezovskiy | a469140 | 2019-03-12 14:18:01 +0400 | [diff] [blame] | 136 | until [[ $(curl -sL -w "%{http_code}" ${j_host}:${j_port}${j_prefix} -o /dev/null) == 200 ]] || [ $wait_time -eq 20 ]; do |
Ivan Berezovskiy | 11d374b | 2018-11-26 18:00:23 +0400 | [diff] [blame] | 137 | sleep $(( wait_time++ )) |
| 138 | done |
| 139 | } |
| 140 | |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 141 | function process_swarm() { |
Ivan Berezovskiy | a469140 | 2019-03-12 14:18:01 +0400 | [diff] [blame] | 142 | _swarm=$(salt-call --out=newline_values_only pillar.get docker:swarm:advertise_addr) |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 143 | if [[ "${_swarm}" != "" ]]; then |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 144 | salt-call ${SALT_OPTS} state.apply docker.swarm |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 145 | fi |
Ivan Berezovskiy | a469140 | 2019-03-12 14:18:01 +0400 | [diff] [blame] | 146 | _docker_enabled=$(salt-call --out=newline_values_only pillar.get docker:client:enabled | tr "[:upper:]" "[:lower:]") |
| 147 | if [[ "${_docker_enabled}" == "true" ]]; then |
| 148 | salt-call ${SALT_OPTS} state.apply docker.client.images |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 149 | salt-call ${SALT_OPTS} state.apply docker.client |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 150 | fi |
Ivan Berezovskiy | 5f7a80f | 2018-12-17 18:08:31 +0400 | [diff] [blame] | 151 | } |
| 152 | |
Ivan Berezovskiy | fba8094 | 2018-11-16 13:11:44 +0400 | [diff] [blame] | 153 | function process_jenkins() { |
| 154 | # INFO: jenkins is in docker in 2019.x releases |
Ivan Berezovskiy | 040c3c6 | 2018-11-30 16:48:49 +0400 | [diff] [blame] | 155 | if [ -f /opt/jenkins_in_docker ]; then |
| 156 | rm -v /opt/jenkins_in_docker |
Ivan Berezovskiy | fba8094 | 2018-11-16 13:11:44 +0400 | [diff] [blame] | 157 | export JENKINS_HOME=/srv/volumes/jenkins |
Ivan Berezovskiy | a469140 | 2019-03-12 14:18:01 +0400 | [diff] [blame] | 158 | _jenkins_enabled=$(salt-call --out=newline_values_only pillar.get jenkins:client:enabled | tr "[:upper:]" "[:lower:]") |
| 159 | if [[ "${_jenkins_enabled}" == "true" ]]; then |
Ivan Berezovskiy | 11d374b | 2018-11-26 18:00:23 +0400 | [diff] [blame] | 160 | wait_for_jenkins |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 161 | salt-call ${SALT_OPTS} state.apply jenkins.client |
Ivan Berezovskiy | fba8094 | 2018-11-16 13:11:44 +0400 | [diff] [blame] | 162 | fi |
| 163 | else |
| 164 | export JENKINS_HOME=/var/lib/jenkins |
| 165 | systemctl enable jenkins |
| 166 | systemctl start jenkins |
Ivan Berezovskiy | 11d374b | 2018-11-26 18:00:23 +0400 | [diff] [blame] | 167 | wait_for_jenkins |
Ivan Berezovskiy | a469140 | 2019-03-12 14:18:01 +0400 | [diff] [blame] | 168 | _jenkins_enabled=$(salt-call --out=newline_values_only pillar.get jenkins:client:enabled | tr "[:upper:]" "[:lower:]") |
| 169 | if [[ "${_jenkins_enabled}" == "true" ]]; then |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 170 | salt-call ${SALT_OPTS} state.apply jenkins.client |
Ivan Berezovskiy | fba8094 | 2018-11-16 13:11:44 +0400 | [diff] [blame] | 171 | fi |
| 172 | systemctl stop jenkins |
| 173 | find ${JENKINS_HOME}/jenkins.model.JenkinsLocationConfiguration.xml -type f -print0 | xargs -0 sed -i -e "s/10.167.4.15/$SALT_MASTER_DEPLOY_IP/g" |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 174 | fi |
Ivan Berezovskiy | fba8094 | 2018-11-16 13:11:44 +0400 | [diff] [blame] | 175 | |
Ivan Berezovskiy | 73cad8e | 2018-11-23 18:53:13 +0400 | [diff] [blame] | 176 | ssh-keyscan cfg01 > ${JENKINS_HOME}/.ssh/known_hosts && chmod a+r ${JENKINS_HOME}/.ssh/known_hosts || true |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 177 | } |
| 178 | |
azvyagintsev | 9a0d7e5 | 2018-10-17 20:15:22 +0300 | [diff] [blame] | 179 | function process_salt_base(){ |
| 180 | # PROD-21179| PROD-21792 : To describe such trick's around salt.XX state ordering |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 181 | salt-call ${SALT_OPTS} state.apply salt.master |
azvyagintsev | 9a0d7e5 | 2018-10-17 20:15:22 +0300 | [diff] [blame] | 182 | # Wait for salt-master to wake up after restart |
| 183 | sleep 5 |
| 184 | salt-call --timeout=120 test.ping |
| 185 | # Run salt.minion.ca to prepare CA certificate before salt.minion.cert is used |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 186 | salt-call ${SALT_OPTS} state.apply salt.minion.ca |
Ann Taraday | 5a63afc | 2018-12-20 23:00:11 +0400 | [diff] [blame] | 187 | # Add sleep for completion of postponed restart of salt-minion. PROD-25986 |
| 188 | sleep 15 |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 189 | salt-call ${SALT_OPTS} state.apply salt.minion |
azvyagintsev | 9a0d7e5 | 2018-10-17 20:15:22 +0300 | [diff] [blame] | 190 | # Wait for salt-minion to wake up after restart |
| 191 | sleep 5 |
| 192 | salt-call --timeout=120 test.ping |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 193 | salt-call ${SALT_OPTS} state.apply salt |
| 194 | salt-call ${SALT_OPTS} state.apply reclass |
azvyagintsev | 9a0d7e5 | 2018-10-17 20:15:22 +0300 | [diff] [blame] | 195 | } |
| 196 | #== Body ==================================================================# |
| 197 | |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 198 | . /etc/cloud/master_environment |
| 199 | printenv | sort -u |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 200 | |
| 201 | echo "Preparing metadata model" |
| 202 | if [[ -n "${CFG_BOOTSTRAP_DRIVE_URL}" ]]; then |
azvyagintsev | 829bfd8 | 2018-12-19 12:58:17 +0200 | [diff] [blame] | 203 | echo "CFG_BOOTSTRAP_DRIVE_URL detected,downloading..." |
| 204 | _tname="cfg01_${RANDOM}.iso" |
| 205 | _wget_opts="--progress=dot:mega --waitretry=15 --retry-connrefused" |
| 206 | wget ${_wget_opts} -O /${_tname} "${CFG_BOOTSTRAP_DRIVE_URL}" |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 207 | mount -o loop /${_tname} /mnt |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 208 | else |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 209 | mount $(blkid -t TYPE=iso9660 -o device) /mnt |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 210 | fi |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 211 | rsync -av /mnt/mcp/model/ /srv/salt/reclass/ |
| 212 | chown -R root:root /srv/salt/reclass/ || true |
| 213 | find /srv/salt/reclass/classes/ -type d -exec chmod 0755 {} \; |
| 214 | find /srv/salt/reclass/classes/ -type f -exec chmod 0644 {} \; |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 215 | |
| 216 | echo "Configuring salt" |
| 217 | envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 218 | if [ -f /mnt/mcp/gpg/salt_master_pillar.asc ]; then |
Dmitry Pyzhov | 15c0ac4 | 2018-12-11 17:10:08 +0300 | [diff] [blame] | 219 | mkdir /etc/salt/gpgkeys |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 220 | chmod 0700 /etc/salt/gpgkeys |
| 221 | GNUPGHOME=/etc/salt/gpgkeys gpg --import /mnt/mcp/gpg/salt_master_pillar.asc |
Dmitry Pyzhov | 15c0ac4 | 2018-12-11 17:10:08 +0300 | [diff] [blame] | 222 | fi |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 223 | enable_services |
| 224 | |
| 225 | # Wait for salt-master and salt-minion to wake up after restart |
| 226 | salt-call --timeout=120 test.ping |
| 227 | |
| 228 | while true; do |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 229 | salt-key | grep -w "$SALT_MASTER_MINION_ID" && break |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 230 | sleep 5 |
| 231 | done |
| 232 | |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 233 | echo "updating local git repos" |
| 234 | if [[ "$PIPELINES_FROM_ISO" == "true" ]] ; then |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 235 | rsync -av /mnt/mcp/mk-pipelines/ /home/repo/mk/mk-pipelines/ |
| 236 | rsync -av /mnt/mcp/pipeline-library/ /home/repo/mcp-ci/pipeline-library/ |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 237 | umount /mnt || true |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 238 | chown -R git:www-data /home/repo/mk/mk-pipelines /home/repo/mcp-ci/pipeline-library |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 239 | else |
| 240 | umount /mnt || true |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 241 | git clone --mirror "${MK_PIPELINES_URL}" /home/repo/mk/mk-pipelines/ |
| 242 | git clone --mirror "${PIPELINE_LIB_URL}" /home/repo/mcp-ci/pipeline-library/ |
| 243 | chown -R git:www-data /home/repo/mk/mk-pipelines /home/repo/mcp-ci/pipeline-library |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 244 | fi |
| 245 | |
| 246 | process_formulas |
| 247 | |
| 248 | salt-call saltutil.refresh_pillar |
| 249 | salt-call saltutil.sync_all |
| 250 | if ! $(reclass -n ${SALT_MASTER_MINION_ID} > /dev/null ) ; then |
| 251 | echo "ERROR: Reclass render failed!" |
| 252 | exit 1 |
| 253 | fi |
| 254 | |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 255 | salt-call ${SALT_OPTS} state.apply linux.system.repo,linux.network,linux.system,linux,openssh |
azvyagintsev | 9a0d7e5 | 2018-10-17 20:15:22 +0300 | [diff] [blame] | 256 | process_salt_base |
Stanislav Riazanov | 450ceaa | 2018-12-18 20:17:07 +0400 | [diff] [blame] | 257 | |
Ivan Berezovskiy | a469140 | 2019-03-12 14:18:01 +0400 | [diff] [blame] | 258 | systemctl stop apache2 || true |
| 259 | systemctl disable apache2 || true |
| 260 | chmod 0 /etc/init.d/apache2 |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 261 | |
Ivan Berezovskiy | a469140 | 2019-03-12 14:18:01 +0400 | [diff] [blame] | 262 | _kfg_enabled=$(salt-call --out=newline_values_only pillar.get kubernetes:master:enabled | tr "[:upper:]" "[:lower:]") |
| 263 | if [ "${_kfg_enabled}" != "true" ]; then |
| 264 | if [ -f /opt/jenkins_in_docker ] || [ -f /opt/postgresql_in_docker ]; then |
| 265 | process_swarm |
| 266 | fi |
| 267 | if [ -f /opt/jenkins_in_docker ] && [ ! -f /opt/postgresql_in_docker ]; then |
| 268 | docker stack rm postgresql || true |
| 269 | fi |
| 270 | else |
Ivan Berezovskiy | a469140 | 2019-03-12 14:18:01 +0400 | [diff] [blame] | 271 | salt-call ${SALT_OPTS} state.apply etcd.server.service |
| 272 | salt-call ${SALT_OPTS} state.apply kubernetes.master.kube-addons |
| 273 | _images=$(salt-call --out=newline_values_only pillar.get kubernetes:pool:images) |
| 274 | if [ -n "${_images}" ]; then |
| 275 | salt-call ${SALT_OPTS} state.apply kubernetes.pool.images |
| 276 | fi |
| 277 | salt-call ${SALT_OPTS} state.apply kubernetes exclude=kubernetes.master.setup,kubernetes.client |
| 278 | salt-call ${SALT_OPTS} state.apply kubernetes.master |
| 279 | salt-call ${SALT_OPTS} state.apply nginx.server |
| 280 | _ldap_enabled=$(salt-call --out=newline_values_only pillar.get openldap:client:enabled | tr "[:upper:]" "[:lower:]") |
| 281 | if [ "${_ldap_enabled}" == "true" ]; then |
| 282 | salt-call ${SALT_OPTS} state.apply openldap.client |
| 283 | fi |
| 284 | _gerrit_enabled=$(salt-call --out=newline_values_only pillar.get gerrit:client:enabled | tr "[:upper:]" "[:lower:]") |
| 285 | if [ "${_gerrit_enabled}" == "true" ]; then |
| 286 | salt-call ${SALT_OPTS} state.apply gerrit.client |
| 287 | fi |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 288 | fi |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 289 | |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 290 | process_jenkins |
Stanislav Riazanov | c69bfc0 | 2018-12-07 16:52:14 +0400 | [diff] [blame] | 291 | process_maas |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 292 | |
Ivan Berezovskiy | fba8094 | 2018-11-16 13:11:44 +0400 | [diff] [blame] | 293 | stop_services="salt-api salt-master salt-minion maas-rackd.service maas-regiond.service postgresql.service" |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 294 | for s in ${stop_services} ; do |
| 295 | systemctl stop ${s} || true |
| 296 | sleep 1 |
| 297 | done |
azvyagintsev | c1c6204 | 2018-09-26 11:47:49 +0300 | [diff] [blame] | 298 | # Set bootstrap-done flag for future |
| 299 | mkdir -p /var/log/mcp/ |
| 300 | touch /var/log/mcp/.bootstrap_done |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 301 | sync |
Dzmitry Stremkouski | 9dd6a1b | 2019-01-24 12:03:58 +0100 | [diff] [blame] | 302 | shutdown -r now |
Ivan Berezovskiy | 7718717 | 2018-09-14 15:47:36 +0400 | [diff] [blame] | 303 | runcmd: |
azvyagintsev | c1c6204 | 2018-09-26 11:47:49 +0300 | [diff] [blame] | 304 | - [bash, -cex, *master_config] |