diff --git a/playbooks/roles/bifrost-create-vm-nodes/defaults/required_defaults_CentOS.yml b/playbooks/roles/bifrost-create-vm-nodes/defaults/required_defaults_CentOS.yml new file mode 100644 index 000000000..b989bae90 --- /dev/null +++ b/playbooks/roles/bifrost-create-vm-nodes/defaults/required_defaults_CentOS.yml @@ -0,0 +1,20 @@ +--- +libvirt_service_name: libvirtd +required_packages: + - qemu-img + - qemu-kvm-tools + - qemu-kvm + - qemu-kvm-common + - sgabios + - libvirt + - libvirt-client + - libvirt-daemon + - libvirt-daemon-config-network + - libvirt-daemon-config-nwfilter + - libvirt-daemon-driver-network + - libvirt-daemon-driver-nodedev + - libvirt-daemon-driver-nwfilter + - libvirt-daemon-driver-qemu + - libvirt-daemon-driver-secret + - libvirt-daemon-driver-storage + - libvirt-daemon-kvm diff --git a/playbooks/roles/bifrost-create-vm-nodes/defaults/required_defaults_Debian.yml b/playbooks/roles/bifrost-create-vm-nodes/defaults/required_defaults_Debian.yml new file mode 100644 index 000000000..e1e4149a5 --- /dev/null +++ b/playbooks/roles/bifrost-create-vm-nodes/defaults/required_defaults_Debian.yml @@ -0,0 +1,8 @@ +--- +libvirt_service_name: libvirt-bin +required_packages: + - libvirt-bin + - qemu-utils + - qemu-kvm + - qemu-system-x86 + - sgabios diff --git a/playbooks/roles/bifrost-create-vm-nodes/defaults/required_defaults_RedHat.yml b/playbooks/roles/bifrost-create-vm-nodes/defaults/required_defaults_RedHat.yml new file mode 100644 index 000000000..4d3a274ac --- /dev/null +++ b/playbooks/roles/bifrost-create-vm-nodes/defaults/required_defaults_RedHat.yml @@ -0,0 +1,12 @@ +--- +libvirt_service_name: libvirtd +required_packages: + - qemu-img + - qemu-kvm-tools + - qemu-kvm + - qemu-kvm-common + - qemu-system-x86 + - sgabios + - libvirt + - libvirt-client + - libvirt-daemon diff --git a/playbooks/roles/bifrost-create-vm-nodes/files/create_vm_nodes-for-role.sh b/playbooks/roles/bifrost-create-vm-nodes/files/create_vm_nodes-for-role.sh index f7d69d9d2..d5a4d0bc2 100755 --- a/playbooks/roles/bifrost-create-vm-nodes/files/create_vm_nodes-for-role.sh +++ b/playbooks/roles/bifrost-create-vm-nodes/files/create_vm_nodes-for-role.sh @@ -38,6 +38,15 @@ VM_EMULATOR=${VM_EMULATOR:-/usr/bin/qemu-system-x86_64} VM_CPU=${VM_CPU:-1} VM_RAM=${VM_RAM:-3072} VM_DISK=${VM_DISK:-10} +VM_MACHINE="pc-1.0" + +# CentOS provides a single emulator package +# which differs from other distributions, and +# needs to be explicitly set. +if [ -e /etc/centos-release ]; then + VM_EMULATOR=/usr/libexec/qemu-kvm + VM_MACHINE="pc" +fi # VM network VM_NET_BRIDGE=${VM_NET_BRIDGE:-default} @@ -95,6 +104,12 @@ function create_node { if [ -n "$LOGDIR" ] ; then mkdir -p "$LOGDIR" + if [ -e /etc/centos-release ]; then + # NOTE(TheJulia): For some unknown reason, libvirt's log folder permissions + # on CentOS ship in an inoperable state. Users must be able to read a folder + # to open files in the folder structure. + chmod o+rx "$LOGDIR/.." + fi fi PREALLOC= @@ -112,15 +127,20 @@ function create_node { volume_path=$(virsh vol-path --pool $LIBVIRT_STORAGE_POOL $VOL_NAME) # Pre-touch the VM to set +C, as it can only be set on empty files. touch "$volume_path" - chattr +C "$volume_path" || true + # NOTE(TheJulia): CentOS default installs with an XFS root, and chattr + # fails to set +C on XFS. This could be more elegent, however the use + # case is for CI testing. + if [ ! -e /etc/centos-release ]; then + chattr +C "$volume_path" || true + fi vm_xml=" ${NAME} ${MEM} ${CPU} - hvm + hvm diff --git a/playbooks/roles/bifrost-create-vm-nodes/tasks/main.yml b/playbooks/roles/bifrost-create-vm-nodes/tasks/main.yml index f6756b1b5..ebbc7714b 100644 --- a/playbooks/roles/bifrost-create-vm-nodes/tasks/main.yml +++ b/playbooks/roles/bifrost-create-vm-nodes/tasks/main.yml @@ -14,27 +14,16 @@ # # TODO: Consider converting to ansible virt module. --- -- name: "Install testing apt packages for Ubuntu/Debian" - when: ansible_os_family == 'Debian' - apt: name={{ item }} state=present - with_items: - - libvirt-bin - - qemu-utils - - qemu-kvm - - qemu-system-x86 - - sgabios -- name: "Install testing yum packages for RedHat/CentOS/Fedora/OpenSuse" - when: ansible_os_family in ['CentOS', 'Fedora', 'OpenSuse', 'RedHat'] - yum: name={{ item }} state=present - with_items: - - libvirt-client - - qemu-img - - qemu-kvm-tools - - qemu-kvm - - qemu-system-x86 - - sgabios +- name: "Load Distribution defaults" + include_vars: "{{ item }}" + with_first_found: + - "../defaults/required_defaults_{{ ansible_distribution }}.yml" + - "../defaults/required_defaults_{{ ansible_os_family }}.yml" +- name: "Install required packages" + action: "{{ ansible_pkg_mgr }} name={{item}} state=present" + with_items: required_packages - name: "Restart libvirt service" - service: name=libvirt-bin state=restarted + service: name={{libvirt_service_name}} state=restarted - name: "Create virtual machines" script: create_vm_nodes-for-role.sh environment: