Petr Michalec | 8abadb1 | 2018-03-16 15:12:44 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | ## ----------------------------------------------------------------------------- |
| 4 | # PREREQ |
| 5 | if [ -e /tmp/kitchen ]; then |
| 6 | rsync -avh --force --exclude "**/.kitchen" /tmp/kitchen/ /srv/salt/reclass |
| 7 | fi |
| 8 | source /srv/salt/bootstrap.sh |
| 9 | source_local_envs |
| 10 | |
| 11 | # FULL BOOTSTRAP |
| 12 | # make sure everything is set-up and exactly as in the model |
| 13 | if [[ $BOOTSTRAP =~ ^(True|true|1|yes)$ ]]; then |
| 14 | cd /srv/salt/reclass |
| 15 | if [[ -e .gitmodules ]] && [[ ! -e classes/system/linux ]]; then |
| 16 | git submodule update --init --recursive --remote || true |
| 17 | fi |
| 18 | /srv/salt/bootstrap.sh &&\ |
| 19 | if [[ -e /tmp/kitchen ]]; then sed -i '/BOOTSTRAP=/d' /kitchen.env; fi || exit 1 |
| 20 | else |
| 21 | # JUST CONFIGURE AND START SALT-MASTER |
| 22 | # minimal setup to speed up, good-enough for model validation |
| 23 | mkdir -p /srv/salt/reclass/nodes/_generated; |
| 24 | cat <<-EOF > /srv/salt/reclass/nodes/_generated/cfg01.$CLUSTER_NAME.local.yml |
| 25 | classes: |
| 26 | - cluster.$CLUSTER_NAME.infra.config |
| 27 | parameters: |
| 28 | _param: |
| 29 | linux_system_codename: xenial |
| 30 | reclass_data_revision: |
| 31 | reclass_data_repository: |
| 32 | cluster_name: $CLUSTER_NAME |
| 33 | cluster_domain: local |
| 34 | linux: |
| 35 | system: |
| 36 | name: cfg01 |
| 37 | domain: $CLUSTER_NAME.local |
| 38 | reclass: |
| 39 | storage: |
| 40 | data_source: |
| 41 | engine: local |
| 42 | EOF |
| 43 | # RECLASS PREREQUISITES |
| 44 | # remove lock if you need (re)configure salt-master, reclass 2nd time |
| 45 | if [ ! -e /tmp/.reclass-prerequisite-once.lock ]; then |
| 46 | # link services (subject of future changes) |
| 47 | if [ ! -e /srv/salt/reclass/classes/service -a -e /usr/share/salt-formulas/reclass/service ]; then |
| 48 | rm -rf /srv/salt/reclass/classes/service || true; |
| 49 | ln -sf /usr/share/salt-formulas/reclass/service /srv/salt/reclass/classes |
| 50 | fi &&\ |
| 51 | # reload |
| 52 | service salt-master force-reload &&\ |
| 53 | service salt-minion force-reload &&\ |
| 54 | retry salt-call saltutil.sync_all &&\ |
| 55 | # generate static nodes |
| 56 | PILLAR='{"reclass":{"storage":{"data_source":{"engine":"local"}}} }' &&\ |
| 57 | salt-call state.apply reclass.storage.node pillar="$PILLAR" &&\ |
| 58 | # generate/mockup dynamic nodes (uses fn from bootstrap.sh) |
| 59 | mockup_node_registration &&\ |
| 60 | touch /tmp/.salt-services-reload-once.lock || exit 1 |
| 61 | fi |
| 62 | fi |
| 63 | |
| 64 | |
| 65 | |
| 66 | ## ----------------------------------------------------------------------------- |
| 67 | ## VERIFY MASTER AND MINIONS |
| 68 | |
| 69 | if [[ ! -e /tmp/.verify-prerequisite-once.lock && ! $RECLASS_IGNORE_CLASS_NOTFOUND =~ ^(True|true|1|yes)$ ]]; then |
| 70 | sed -i 's/ignore_class_notfound:\s*True.*/ignore_class_notfound: False/' /etc/salt/master.d/reclass.conf |
| 71 | sed -i 's/ignore_class_notfound:\s*True.*/ignore_class_notfound: False/' /etc/reclass/reclass-config.yml |
| 72 | service salt-master force-reload |
| 73 | retry salt-call test.ping |
| 74 | fi |
| 75 | |
| 76 | cd /srv/salt/reclass &&\ |
| 77 | if [[ -z "$1" ]] ; then |
| 78 | verify_salt_master &&\ |
| 79 | verify_salt_minions |
| 80 | else |
| 81 | verify_salt_minion "$1" |
| 82 | fi |