blob: 9c193fa7dc327cf523902466e5eb39c30462c570 (
plain)
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
|
#!/bin/bash
# Premier numero de la série
index=3
# Nombre de machines
count=1
# Déploiment terraform
terraform init -reconfigure
terraform plan
terraform apply -var "nb=$count" -var "start=$index" -auto-approve
echo
# On copie notre clé publique et on met à jour le hostname des machines
for ((i=$index;i<$((index+count));i++));do
vm=ubuntu$i
while vboxmanage guestproperty get $vm /VirtualBox/GuestInfo/Net/0/V4/IP |grep -q "No value"; do
sleep 5
echo "Wait VM until ready..."
done
echo -e "\n [$vm ip] $(vboxmanage guestproperty get $vm /VirtualBox/GuestInfo/Net/0/V4/IP)"
vboxmanage guestcontrol $vm --username vagrant --password vagrant copyto id_rsa.pub /home/vagrant/.ssh/authorized_keys
vboxmanage guestcontrol $vm --username vagrant --password vagrant copyto set-hostname /home/vagrant/set-hostname
vboxmanage guestcontrol $vm --username vagrant --password vagrant run /usr/bin/bash /home/vagrant/set-hostname $vm
done
echo
|