summaryrefslogtreecommitdiff
path: root/create-vm
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-07-03 22:14:26 +0300
committerLars Wirzenius <liw@liw.fi>2015-07-03 22:14:26 +0300
commit662fac8a7a4877876769d01c3f3c8a4480963c17 (patch)
tree768b9657827b36ef960a6d16ecd0ad42d2ab89b1 /create-vm
parent2869f07a36149688615bc71757240947b448fe1f (diff)
downloadansibleness-662fac8a7a4877876769d01c3f3c8a4480963c17.tar.gz
Add preliminary README and VM creation script
Diffstat (limited to 'create-vm')
-rw-r--r--create-vm48
1 files changed, 48 insertions, 0 deletions
diff --git a/create-vm b/create-vm
new file mode 100644
index 0000000..1be7694
--- /dev/null
+++ b/create-vm
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# Create a new VM for liw.
+
+set -eu
+
+# Command line parameters: name of VM and base image (no .img.xz suffix).
+name="$1"
+base="$2"
+
+# Where are the base images?
+imagedir="/big/base-images"
+
+# How large are the (uncompressed) images?
+imagesize="4G"
+
+# What volume group should we use?
+vg="exolobe1-vg"
+
+# Create new LV.
+lvcreate --name "$name" --size "$imagesize" "$vg"
+lvpath="/dev/$vg/$name"
+
+# Copy uncompressed image to LV.
+unxz < "$imagedir/$base.img.xz" | pv --size "$size" > "$lvpath"
+
+# Create VM.
+virt-install -c qemu:///system \
+ --name="$name" \
+ --memory=512 \
+ --cpu=host-model-only \
+ --import \
+ --os-variant=debianwheezy \
+ --disk="path=$lvpath,cache=none" \
+ --network=network=default \
+ --graphics=spice
+
+# 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