7f2c3cac7012d3e23c463ffe93c8e3a2849413a2
[fuel.git] / mcp / scripts / salt.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2017 Mirantis Inc., Enea AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 #
10 # Deploy Salt Master
11 #
12
13 F_GIT_ROOT=$(git rev-parse --show-toplevel)
14 OPNFV_TMP_DIR="/home/${SALT_MASTER_USER}/fuel"
15 OPNFV_FUEL_DIR="/root/fuel"
16
17 # patch reclass-system-salt-model locally before copying it over
18 make -C "${F_GIT_ROOT}/mcp/patches" deepclean patches-import
19
20 # push to cfg01 current git repo first (including submodules), at ~ubuntu/fuel
21 # later we move it to ~root/fuel and delete the temporary clone
22 rsync -Erl --delete -e "ssh ${SSH_OPTS}" \
23   --exclude-from="${F_GIT_ROOT}/.gitignore" \
24   "${F_GIT_ROOT}/" "${SSH_SALT}:$(basename "${OPNFV_TMP_DIR}")/"
25
26 # ssh to cfg01
27 # shellcheck disable=SC2086,2087
28 ssh ${SSH_OPTS} "${SSH_SALT}" bash -s << SALT_INSTALL_END
29   sudo -i
30
31   echo -n 'Checking out cloud-init has finished running ...'
32   while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo -n '.'; sleep 1; done
33   echo ' done'
34
35   mkdir -p /srv/salt /usr/share/salt-formulas/reclass
36   mv ${OPNFV_TMP_DIR} ${OPNFV_FUEL_DIR} && chown -R root.root ${OPNFV_FUEL_DIR}
37   ln -s ${OPNFV_FUEL_DIR}/mcp/reclass /srv/salt/reclass
38   ln -s ${OPNFV_FUEL_DIR}/mcp/deploy/scripts /srv/salt/scripts
39   cd /srv/salt/reclass/classes/cluster/all-mcp-ocata-common && \
40     ln -s "\$(uname -i)" arch
41
42   cp -r ${OPNFV_FUEL_DIR}/mcp/metadata/service /usr/share/salt-formulas/reclass
43   cd /srv/salt/reclass/classes/service && \
44     ln -s /usr/share/salt-formulas/reclass/service/opendaylight
45   cd ${OPNFV_FUEL_DIR}/mcp/patches && ./patch.sh patches.list reclass
46
47   cd /srv/salt/scripts
48   BOOTSTRAP_SALTSTACK_OPTS=" -r -dX stable 2016.11 " \
49     MASTER_HOSTNAME=cfg01.${CLUSTER_DOMAIN} DISTRIB_REVISION=nightly \
50       ./salt-master-init.sh
51   salt-key -Ay
52
53   cp -r ${OPNFV_FUEL_DIR}/mcp/salt-formulas/* /usr/share/salt-formulas/env
54   cd ${OPNFV_FUEL_DIR}/mcp/patches && ./patch.sh patches.list formulas
55
56   salt-call state.apply salt
57   salt '*' saltutil.sync_all
58   salt '*' state.apply salt | fgrep -q 'No response' && salt '*' state.apply salt
59
60   salt -C 'I@salt:master' state.sls linux
61   salt -C '* and not cfg01*' state.sls linux
62
63   salt '*' state.sls ntp
64 SALT_INSTALL_END