-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti-ble.sh
executable file
·69 lines (56 loc) · 1.22 KB
/
multi-ble.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
set -e
export ANSIBLE_CONFIG=.ansible.cfg
vms=(login-1 login-2)
# delete all, if any, currently existing VMs that we are going to configure from scratch
delete () {
printf "deleting currently running VMs\n"
for vm in ${vms[@]}; do
multipass delete -p $vm && printf "deleted $vm\n" || continue
done
}
# start all VMs in a loop and configure a bare minimum with the cloud-init.yaml file
launch () {
printf "\nstarting and configuring VMs with multipass and cloud-init\n"
for vm in ${vms[@]}; do
multipass launch --name $vm --cloud-init cloud-init.yaml 20.04
done
}
# create a fresh hosts file so you don't need to edit the ip addresses manually
list () {
printf "\nupdating the hosts file\n"
multipass list | tail -n +2 | awk '{ print "[", $1, "]", "\n", $3}' | sed -e 'n;$!G' | sed 's| ||g' > hosts
}
# finally run ansible and configure the VMs
ansible () {
printf "\nrunning ansible\n"
ansible-playbook -i hosts -u ubuntu main.yml
}
case $1 in
all)
delete
launch
list
ansible
;;
purge)
delete
;;
launch)
delete
launch
list
;;
ansible)
ansible
;;
*)
echo "Command '$1' not recognized"
echo "Valid commands"
echo "all"
echo "purge"
echo "launch"
echo "ansible"
exit
;;
esac