4 # shellcheck disable=SC1090
5 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/lib.sh"
7 # Wait for MaaS commissioning/deploy to finish, retry on failure
8 function maas_fixup() {
9 local statuscmd="salt 'mas01*' --out yaml state.apply maas.machines.status"
10 # shellcheck disable=SC2155
11 local ncount=$(salt --out yaml 'mas01*' pillar.get maas:region:machines | \
12 grep -cE '^\s{2}\w+:$')
13 wait_for 180 "${statuscmd} | tee /dev/stderr | " \
14 "grep -Eq '((Deployed|Ready): ${ncount}|status:Failed|status:Allocated)'"
15 # shellcheck disable=SC2155
16 local statusout=$(eval "${statuscmd}")
18 # shellcheck disable=SC2155
19 local fcnodes=$(echo "${statusout}" | \
20 grep -Po '(?<=system_id:)(.*)(?=,status:Failed commissioning)')
21 for node_system_id in ${fcnodes}; do
22 salt -C 'mas01*' state.apply maas.machines.delete \
23 pillar="{'system_id': '${node_system_id}'}"
26 if [ -n "${fcnodes}" ]; then
27 salt -C 'mas01*' state.apply maas.machines
31 # shellcheck disable=SC2155
32 local fdnodes=$(echo "${statusout}" | \
33 grep -Po '(?<=system_id:)(.*)(?=,status:(Failed deployment|Allocated))')
34 for node_system_id in ${fdnodes}; do
35 salt -C 'mas01*' state.apply maas.machines.mark_broken_fixed \
36 pillar="{'system_id': '${node_system_id}'}"
39 if [ -n "${fdnodes}" ]; then
40 salt -C 'mas01*' state.apply maas.machines.deploy
47 # MaaS rack/region controller, node commissioning
48 salt -C 'mas01*' cmd.run "add-apt-repository ppa:maas/stable"
50 salt -C 'mas01*' state.apply linux,salt,openssh,ntp
51 salt -C 'mas01*' state.apply linux.network.interface
52 salt -C 'mas01*' state.apply maas.pxe_nat
53 salt -C 'mas01*' state.apply maas.cluster
54 salt -C 'cfg01*' state.apply maas.pxe_route
56 wait_for 10 "salt -C 'mas01*' state.apply maas.region"
58 salt -C 'mas01*' state.apply maas.machines
59 wait_for 10 maas_fixup
61 # cleanup outdated salt keys
62 salt-key --out yaml | awk '!/^(minions|- cfg01|- mas01)/ {print $2}' | \
63 xargs -I{} salt-key -yd {}
65 # MaaS node deployment
66 salt -C 'mas01*' state.apply maas.machines.deploy
67 wait_for 10 maas_fixup
69 salt -C 'mas01*' pillar.item\
70 maas:region:admin:username \
71 maas:region:admin:password
73 salt -C '* and not cfg01* and not mas01*' saltutil.sync_all