From 14b77f458ae58b6de132110a8a4fe54065cf0f4a Mon Sep 17 00:00:00 2001 From: jerome Date: Mon, 12 Sep 2022 21:19:27 +0200 Subject: update main.tf createvm --- .terraform.tfstate.lock.info | 2 +- createvm | 16 +++++++++++----- main.tf | 13 +++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.terraform.tfstate.lock.info b/.terraform.tfstate.lock.info index 446e4c5..1d6e23b 100644 --- a/.terraform.tfstate.lock.info +++ b/.terraform.tfstate.lock.info @@ -1 +1 @@ -{"ID":"2124f887-5245-88c0-5bb6-7d406c0c3482","Operation":"OperationTypeApply","Info":"","Who":"jerome@jerome-laptop","Version":"1.2.9","Created":"2022-09-11T16:56:46.417100086Z","Path":"terraform.tfstate"} \ No newline at end of file +{"ID":"e03046f8-ad39-9e8a-a070-e49aa5b7f138","Operation":"OperationTypeApply","Info":"","Who":"jerome@jerome-laptop","Version":"1.2.9","Created":"2022-09-12T19:18:21.247926075Z","Path":"terraform.tfstate"} \ No newline at end of file diff --git a/createvm b/createvm index 509fd90..9c193fa 100755 --- a/createvm +++ b/createvm @@ -10,13 +10,19 @@ terraform init -reconfigure terraform plan terraform apply -var "nb=$count" -var "start=$index" -auto-approve -sleep 5 +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 -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 + 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 diff --git a/main.tf b/main.tf index 1410f7f..624c7e4 100644 --- a/main.tf +++ b/main.tf @@ -23,12 +23,13 @@ resource "virtualbox_vm" "node" { } } -output "ip_addresses" { - value = { - for vm in virtualbox_vm.node.*: - vm.name => vm.network_adapter.0.ipv4_address - } -} +# bug : timeout... +#output "ip_addresses" { +# value = { +# for vm in virtualbox_vm.node.*: +# vm.name => vm.network_adapter.0.ipv4_address +# } +#} ######################### # Principales commandes # -- cgit v1.2.3