6 local total_attempts=360
9 echo "[NOTE] Waiting for cmd to return success: ${cmdstr}"
10 while ((attempt <= total_attempts)); do
11 eval "${cmdstr}" && break || true
12 echo -n '.'; sleep "${sleep_time}"
17 # MaaS rack/region controller, node commissioning
18 salt -C 'mas01*' cmd.run "add-apt-repository ppa:maas/stable"
20 salt -C 'mas01*' state.apply linux,salt,openssh,ntp
21 salt -C 'mas01*' state.apply linux.network.interface
22 salt -C 'mas01*' state.apply maas.pxe_nat
23 salt -C 'mas01*' state.apply maas.cluster
24 salt -C 'cfg01*' cmd.run \
25 "route add -net 192.168.11.0/24 gw ${MAAS_IP:-192.168.10.3}"
27 wait_for "salt -C 'mas01*' state.apply maas.region"
29 salt -C 'mas01*' state.apply maas.machines
30 # TODO: relax cond, as this is not re-entrant (e.g. nodes already deployed)
31 wait_for "salt 'mas01*' --out yaml state.apply maas.machines.status | " \
32 "tee /dev/stderr | fgrep -q 'Ready: 5'"
34 # cleanup outdated salt keys
35 salt-key --out yaml | awk '!/^(minions|- cfg01|- mas01)/ {print $2}' | xargs -I{} salt-key -yd {}
37 # MaaS node deployment
38 salt -C 'mas01*' state.apply maas.machines.deploy
39 wait_for "salt 'mas01*' --out yaml state.apply maas.machines.status | " \
40 "tee /dev/stderr | fgrep -q 'Deployed: 5'"
42 salt -C 'mas01*' pillar.item\
43 maas:region:admin:username \
44 maas:region:admin:password
46 # KVM, compute node prereqs (libvirt first), VCP deployment
47 salt -C '* and not cfg01* and not mas01*' saltutil.sync_all
49 salt -C 'kvm*' pkg.install bridge-utils
50 salt -C 'kvm*' state.apply linux.network
51 salt -C 'kvm*' system.reboot
52 wait_for "! salt '*' test.ping | tee /dev/stderr | fgrep -q 'Not connected'"
54 salt -C '* and not cfg01* and not mas01*' state.apply linux,ntp
56 salt -C 'kvm*' state.sls libvirt
58 salt -C '* and not cfg01* and not mas01*' state.apply salt
59 salt -C 'kvm*' saltutil.sync_all
60 salt -C 'kvm*' state.sls salt.control
62 vcp_nodes=$(salt --out yaml 'kvm01*' pillar.get salt:control:cluster:internal:node | awk '/\s+\w+:$/ {gsub(/:$/, "*"); print $1}')
64 # Check all vcp nodes are available
66 while [ $rc -ne 0 ]; do
68 for node in $vcp_nodes; do
69 salt "$node" test.ping 2>/dev/null || { rc=$?; break; };
74 wait_for "salt -C '* and not cfg01* and not mas01*' ssh.set_auth_key ${SUDO_USER} \
75 $(awk 'NR==1{print $2}' $(eval echo ~${SUDO_USER}/.ssh/authorized_keys))"
77 wait_for "salt -C '* and not cfg01* and not mas01*' saltutil.sync_all"
78 salt -C '* and not cfg01* and not mas01*' state.apply salt
79 wait_for "salt -C '* and not cfg01* and not mas01*' state.apply linux,ntp"