Commit e73783b4 authored by Dennis Baurichter's avatar Dennis Baurichter
Browse files

Remove relentless and libvirt role

The VMs will be hosted at the IRB now.
parent fe2aeea7
---
pull_groups:
- server
- datacenter
network_ansible: br0
network:
bond0:
type: bond
mode: 802.3ad
mac: 52:54:00:42:17:e2
device:
ens3:
mac: 52:54:00:6e:78:73
ens4:
mac: 52:54:00:1b:9f:bb
ens5:
mac: 52:54:00:bd:71:0a
ens6:
mac: 52:54:00:af:4e:e9
virtualization: true
br0:
type: bridge
device: bond0
gateway4: 131.234.187.193
gateway6: 2001:638:502:1875::1
ipv6: 2001:638:502:1875:80:0:210:1/64
ipv4: 131.234.187.210/26
dhcp: false
lldp: true
virtualization: true
......@@ -36,7 +36,7 @@
ansible_pull:
url: https://git.cs.uni-paderborn.de/rbfsmi/rbfsmi-ansible.git
branch: master
post_tasks:
- name: configure per-host kernel settings
sysctl:
......@@ -275,11 +275,6 @@
roles:
- role: ipxe-update
- name: install libvirt environment
hosts: fsmi-relentless-relentless
roles:
- role: libvirt
- name: configure fsmi-matrix
hosts: fsmi-matrix
roles:
......
nvram = [
"/usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd",
"/usr/share/OVMF/OVMF_CODE.secboot.fd:/usr/share/OVMF/OVMF_VARS.fd"
]
#!/bin/bash
# should contain directories images and cdimages
readonly DISK_ROOT='/var/lib/libvirt/'
readonly VM_OS_TYPE='Linux'
readonly VM_OS_VARIANT='archlinux'
VM_BOOTSTRAP_PARAMETER=(--vm --allow-disk-wipe)
readonly HOST_EFI='/usr/share/edk2-ovmf/x64/OVMF_CODE.fd'
readonly HOST_EFI_NVRAM='/usr/share/edk2-ovmf/x64/OVMF_VARS.fd'
#FILE_SHARE_HOST='/tmp/foo'
#FILE_SHARE_VM='/opt/foo'
BOOTSTRAP_URL='https://git.cs.uni-paderborn.de/rbfsmi/rbfsmi-ansible/-/raw/master/bootstrap.sh'
NAMESERVER='131.234.137.23 131.234.8.254'
if [[ $# -eq 0 ]]; then
>&2 echo "Error: You have to specify arguments"
>&2 echo "Try '$0 --help'"
exit 1
fi
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
echo "Usage: $0 --name VM_NAME --description VM_DESCRIPTION --ram VM_RAM --vcpus VM_CPUS --disk-size DISK_SIZE --bridge BRIDGE --ip VM_IP --gateway VM_GATEWAY [--bootstrap BOOTSTRAP_PATH] [--dns NAMESERVER] [-- BOOTSTRAPPARAM...]"
echo " --name VM_NAME"
echo " Specifies the name of the VM."
echo " --description VM_DESCRIPTION"
echo " Specifies the description of the VM."
echo " --ram VM_RAM"
echo " Specifies the amount of memory of the VM."
echo " Sizes are in MB. Write only numbers."
echo " --vcpus VM_CPU"
echo " Specifies the number of vcpus of the VM."
echo " --disk-size DISK_SIZE"
echo " Specifies the size of disk size of the VM."
echo " Define size in x{K,M,G}."
echo " --bridge BRIDGE"
echo " Like br0."
echo " --ip VM_IP"
echo " IPv4 or IPv6 address of the vm. Use CIDR notation "
echo " --gateway VM_GATEWAY"
echo " IPv4 or IPv6 of the gateway "
echo " --bootstrap BOOTSTRAP_PATH"
echo " Give an alternative path or URI for the bootstrap.sh script."
echo " This is intended for development purposes only."
echo " --dns NAMESERVER"
echo " Give an alternative nameserver, e.g. when testing from outside the university network."
echo " This is intended for development purposes only."
echo " BOOTSTRAPPARAM"
echo " Everything following -- is passed to bootstrap.sh."
echo " --hostname, --vm and --allow-disk-wipe are set explicitly in this script."
exit 0
;;
--name)
if [ -z "$2" ]; then
>&2 echo "missing vm name."
exit 1
fi
readonly VM_NAME="$2"
shift 1
;;
--description)
if [ -z "$2" ]; then
>&2 echo "missing vm description."
exit 1
fi
readonly VM_DESCRIPTION="$2"
shift 1
;;
--vcpus)
if [ -z "$2" ]; then
>&2 echo "missing vcpu amount."
exit 1
fi
readonly VM_VCPUS="$2"
shift 1
;;
--ram)
if [ -z "$2" ]; then
>&2 echo "missing ram size"
exit 1
fi
readonly VM_RAM="$2"
shift 1
;;
--disk-size)
if [ -z "$2" ]; then
>&2 echo "missing vm disk size."
exit 1
fi
readonly DISK_SIZE="$2"
shift 1
;;
--bridge)
if [ -z "$2" ]; then
>&2 echo "missing bridge name."
exit 1
fi
readonly VM_NETWORK="$2"
shift 1
;;
--ip)
if [ -z "$2" ]; then
>&2 echo "missing IP."
exit 1
fi
readonly VM_IP="$2"
shift 1
;;
--gateway)
if [ -z "$2" ]; then
>&2 echo "missing gateway."
exit 1
fi
readonly VM_GATEWAY="$2"
shift 1
;;
--bootstrap)
if [ -z "$2" ]; then
>&2 echo "missing bootstrap.sh path."
exit 1
fi
readonly BOOTSTRAP_URL="$2"
shift 1
;;
--dns)
if [ -z "$2" ]; then
>&2 echo "missing nameserver."
exit 1
fi
readonly NAMESERVER="$2"
shift 1
;;
--)
shift
VM_BOOTSTRAP_PARAMETER+=("$@")
shift "$#"
;;
*)
>&2 echo "Error: Unrecognized option: $1"
>&2 echo "Try '$0 --help'"
exit 1
;;
esac
shift
done
if [ -z "$VM_NAME" -o \
-z "$VM_DESCRIPTION" -o \
-z "$VM_RAM" -o \
-z "$VM_VCPUS" -o \
-z "$VM_NETWORK" -o \
-z "$VM_IP" -o \
-z "$VM_GATEWAY" -o \
-z "$DISK_SIZE" ]; then
>&2 echo "Error: You have not specified all arguments"
>&2 echo "Try '$0 --help'"
fi
readonly DISK_NAME="$(tr '[:space:]/\\' '_' <<< "$VM_NAME")"
readonly VM_DISK="$DISK_ROOT/images/$DISK_NAME"
readonly VM_NVRAM="$DISK_ROOT/nvram/$DISK_NAME-nvram.fd"
readonly VM_CDROM="$DISK_ROOT/cdimages/archlinux-$VM_NAME-$(date +%Y.%m.%d)-x86_64.iso"
create_disk(){
qemu-img create -f qcow2 "$VM_DISK".qcow2 "$DISK_SIZE"
}
install_vm(){
sudo virt-install \
--connect qemu:///system \
--noautoconsole \
--virt-type=kvm \
--boot uefi,loader="$HOST_EFI",loader.readonly=yes,loader.type=pflash,nvram.template="$HOST_EFI_NVRAM",nvram="$VM_NVRAM",loader_secure=no \
-n "$VM_NAME" \
--description "$VM_DESCRIPTION" \
--os-type="$VM_OS_TYPE" \
--os-variant="$VM_OS_VARIANT" \
--ram="$VM_RAM" \
--vcpus="$VM_VCPUS" \
--disk path="$VM_DISK".qcow2,bus=virtio \
--graphics spice \
--serial pty \
--serial pty \
--cdrom "$VM_CDROM" \
--network bridge:"$VM_NETWORK"
#--filesystem source="$FILE_SHARE_HOST",target="$FILE_SHARE_VM",type=mount,accessmode=passthrough
}
create_iso(){
tmpdir="$(mktemp -d --tmpdir tmpdir-archiso-XXXXXX)"
echo "$tmpdir"
cp -r /usr/share/archiso/configs/baseline/* "$tmpdir"
sed -i "s/iso_name.*/iso_name=\"archlinux-$VM_NAME\"/" "$tmpdir/profiledef.sh"
sed -i "s/iso_publisher.*/iso_publisher=\"Lolbot on $(uname -n) <rbfsmi@uni-paderborn.de>\"/" "$tmpdir/profiledef.sh"
sed -i "s/iso_application.*/iso_application=\"Arch Linux baseline for $VM_NAME\"/" "$tmpdir/profiledef.sh"
sed -i '/^file_permissions.*/a\
["/root/rbfsmi-installer.sh"]="0:0:755"\
["/root/bootstrap.sh"]="0:0:755"' "$tmpdir/profiledef.sh"
sed -i '3 a\ SERIAL 0 11520' "$tmpdir/syslinux/syslinux.cfg"
sed -i '/^APPEND/ s/$/ console=ttyS0,115200 console=ttyS1,115200 console=tty0/' "$tmpdir/syslinux/syslinux-linux.cfg"
sed -i '/^options/ s/$/ console=ttyS0,115200 console=ttyS1,115200 console=tty0/' "$tmpdir/efiboot/loader/entries/archiso-x86_64-linux.conf"
mkdir -p "$tmpdir"/airootfs/etc/systemd/system/getty.target.wants/
ln -s /usr/lib/systemd/system/serial-getty@.service "$tmpdir"/airootfs/etc/systemd/system/getty.target.wants/serial-getty@ttyS0.service
ln -s /usr/lib/systemd/system/serial-getty@.service "$tmpdir"/airootfs/etc/systemd/system/getty.target.wants/serial-getty@ttyS1.service
mkdir -p "$tmpdir"/airootfs/etc/systemd/system/multi-user.target.wants/
mkdir -p "$tmpdir"/airootfs/etc/systemd/system/sockets.target.wants/
ln -s /usr/lib/systemd/system/systemd-networkd.service "$tmpdir"/airootfs/etc/systemd/system/dbus-org.freedesktop.network1.service
ln -s /usr/lib/systemd/system/systemd-networkd.service "$tmpdir"/airootfs/etc/systemd/system/multi-user.target.wants/systemd-networkd.service
ln -s /usr/lib/systemd/system/systemd-networkd.socket "$tmpdir"/airootfs/etc/systemd/system/sockets.target.wants/systemd-networkd.socket
cat > "$tmpdir/airootfs/etc/resolv.conf" <<EOF
nameserver $NAMESERVER
search uni-paderborn.de
EOF
cat >> "$tmpdir/packages.x86_64" <<EOF
arch-install-scripts
btrfs-progs
dosfstools
efibootmgr
grub
lvm2
mdadm
parted
xfsprogs
EOF
mkdir -p "$tmpdir/airootfs/etc/systemd/system/getty@tty1.service.d"
cat > "$tmpdir/airootfs/etc/systemd/system/getty@tty1.service.d/autologin.conf" <<EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin root -o '-p -- \\u' --noclear %I $TERM
EOF
mkdir -p "$tmpdir/airootfs/etc/systemd/network"
cat > "$tmpdir/airootfs/etc/systemd/network/20-ethernet.network" <<EOF
[Match]
Name=enp1s0
[Network]
Address=$VM_IP
Gateway=$VM_GATEWAY
EOF
mkdir "$tmpdir/airootfs/root"
cat > "$tmpdir/airootfs/root/.profile" <<EOF
if [[ "\$(tty)" == "/dev/ttyS0" && ! -e /root/.rbfsmi-installer-run ]]; then
touch /root/.rbfsmi-installer-run
/root/rbfsmi-installer.sh
fi
EOF
if [ -e "$BOOTSTRAP_URL" ]; then
cp "$BOOTSTRAP_URL" "$tmpdir/airootfs/root/bootstrap.sh"
else
curl --no-progress-meter --output "$tmpdir/airootfs/root/bootstrap.sh" "$BOOTSTRAP_URL"
fi
cat > "$tmpdir/airootfs/root/rbfsmi-installer.sh" <<EOF
#!/bin/bash
echo "Version: $(date)"
echo "Hostname: $VM_NAME"
echo "Paramter: ${VM_BOOTSTRAP_PARAMETER[*]}"
echo
echo "Installing in 3s..."
sleep 3
echo "Installing now..."
/root/bootstrap.sh --hostname "$VM_NAME" ${VM_BOOTSTRAP_PARAMETER[*]}
EOF
tmpdir_build="$(mktemp -d --tmpdir tmpdir-archiso-build-XXXXXX)"
sudo mkarchiso -v -w "$tmpdir_build" -o "$tmpdir_build/out" "$tmpdir" && \
sudo mv "$tmpdir_build"/out/archlinux-"$VM_NAME"-*.iso "$VM_CDROM" && \
sudo rm -rf "$tmpdir_build"
sudo rm -rf "$tmpdir"
}
create_iso && create_disk && install_vm
---
- name: install programs for libvirt
package:
name: libvirt
name: qemu
name: openbsd-netcat
name: edk2-ovmf
name: gettext
- name: install programs for rbfsmi_vm_install script
package:
name: archiso
name: virt-install
- name: copy qemu.conf to enable efi nvram
copy:
src: qemu.conf
dest: /etc/libvirt/qemu.conf
owner: root
group: root
mode: '0644'
- name: create directories for libvirt
file:
path: "{{ item }}"
state: directory
loop:
- /var/lib/libvirt/cdimages
- /var/lib/libvirt/nvram
- name: install rbfsmi_vm_install script
copy:
src: rbfsmi_vm_install
dest: /usr/local/bin/rbfsmi_vm_install
owner: root
group: root
mode: '0755'
- name: enable and start libvirtd
service:
name: libvirtd
state: started
enabled: yes
- name: enable and start libvirt-guests
service:
name: libvirt-guests
state: started
enabled: yes
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment