diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-07-03 23:05:33 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-07-03 23:05:33 +0300 |
commit | 4a23a547700240d431cda2c07b4a31addd6a43bb (patch) | |
tree | fc772f7f8523cf54e9150490ecddc54d4f6391aa /create-vm | |
parent | 71224534b106fac2c6d57fd4518ab9ec9c8f3cc8 (diff) | |
download | ansibleness-4a23a547700240d431cda2c07b4a31addd6a43bb.tar.gz |
Fix create-vm so it works
This has now been tested several times.
Diffstat (limited to 'create-vm')
-rwxr-xr-x[-rw-r--r--] | create-vm | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/create-vm b/create-vm index 1be7694..3e8d9b8 100644..100755 --- a/create-vm +++ b/create-vm @@ -12,20 +12,23 @@ base="$2" imagedir="/big/base-images" # How large are the (uncompressed) images? -imagesize="4G" +size="4G" # What volume group should we use? vg="exolobe1-vg" # Create new LV. -lvcreate --name "$name" --size "$imagesize" "$vg" +sudo lvcreate --name "$name" --size "$size" "$vg" lvpath="/dev/$vg/$name" # Copy uncompressed image to LV. -unxz < "$imagedir/$base.img.xz" | pv --size "$size" > "$lvpath" +unxz < "$imagedir/base-$base.img.xz" | + pv --size "$size" | + sudo tee "$lvpath" > /dev/null # Create VM. -virt-install -c qemu:///system \ +virt-install --connect qemu:///system \ + --quiet \ --name="$name" \ --memory=512 \ --cpu=host-model-only \ @@ -33,16 +36,27 @@ virt-install -c qemu:///system \ --os-variant=debianwheezy \ --disk="path=$lvpath,cache=none" \ --network=network=default \ - --graphics=spice + --graphics=spice \ + --noautoconsole # Get the MAC address. mac="$(virsh dumpxml "$name" | sed -n "/<mac address=/s/^.*'\(.*\)'.*/\1/p")" # Get IP address related to the MAC address. Append that to /etc/hosts. leases=/var/lib/libvirt/dnsmasq/default.leases -ip="$(awk -v "mac=$mac" '$2 == mac { print $3 }' "$leases")" -echo "$ip $name" >> /etc/hosts - -# Log into VM, change hostname and reboot. -echo "$name" ssh "ansible@$name" tee /etc/hostname -ssh "ansible@$name" reboot +ip="" +while [ "$ip" = "" ] +do + sleep 1 + ip="$(awk -v "mac=$mac" '$2 == mac { print $3 }' "$leases")" +done +echo "$ip $name" | sudo tee -a /etc/hosts > /dev/null + +# Wait for ssh port to be open. +while ! ssh "ansible@$name" true +do + sleep 1 +done + +# Done. +echo "Virtual machine $name ($ip) has been created, and is ready." |