+info() {
+ _print_msg "INFO" "$1"
+}
+
+error() {
+ _print_msg "ERROR" "$1"
+ exit 1
+}
+
+_print_msg() {
+ echo "$(date +%H:%M:%S) - $1: $2"
+}
+
+assert_non_empty() {
+ if [ -z "$1" ]; then
+ error "$2"
+ fi
+}
+
+check_prerequisites() {
+ info "Check prerequisites"
+
+ #-------------------------------------------------------------------------------
+ # We shouldn't be running as root
+ #-------------------------------------------------------------------------------
+ if [[ "$(whoami)" == "root" ]]; then
+ error "This script must not be run as root! Please switch to a regular user before running the script."
+ fi
+
+ #-------------------------------------------------------------------------------
+ # Check for passwordless sudo
+ #-------------------------------------------------------------------------------
+ if ! sudo -n "true"; then
+ error "passwordless sudo is needed for '$(id -nu)' user."
+ fi
+
+ #-------------------------------------------------------------------------------
+ # Check if SSH key exists
+ #-------------------------------------------------------------------------------
+ if [[ ! -f "$HOME/.ssh/id_rsa" ]]; then
+ error "You must have SSH keypair in order to run this script!"
+ fi
+
+ #-------------------------------------------------------------------------------
+ # We are using sudo so we need to make sure that env_reset is not present
+ #-------------------------------------------------------------------------------
+ sudo sed -i "s/^Defaults.*env_reset/#&/" /etc/sudoers
+
+ #-------------------------------------------------------------------------------
+ # Check if some tools are installed
+ #-------------------------------------------------------------------------------
+ for tool in ansible yq virsh; do
+ if ! command -v "$tool" &> /dev/null; then
+ error "$tool not found. Please install."
+ fi
+ done
+
+ #-------------------------------------------------------------------------------
+ # Check if user belongs to libvirt's group
+ #-------------------------------------------------------------------------------
+ libvirt_group="libvirt"
+ # shellcheck disable=SC1091
+ source /etc/os-release || source /usr/lib/os-release
+ if [ "${ID,,}" == "ubuntu" ] && [ "$VERSION_ID" == "16.04" ]; then
+ libvirt_group+="d"