diff --git a/.github/workflows/vagrant-up.yml b/.github/workflows/vagrant-up.yml index 42504ed..19a5754 100644 --- a/.github/workflows/vagrant-up.yml +++ b/.github/workflows/vagrant-up.yml @@ -22,7 +22,7 @@ jobs: run: sudo apt-get update - name: install packages - run: sudo apt install -y virtualbox virtualbox-guest-utils virtualbox-guest-x11 vagrant git + run: sudo apt install -y virtualbox virtualbox-guest-utils virtualbox-guest-x11 vagrant git qemu-system - name: init submodules run: git submodule update --init --recursive @@ -30,16 +30,19 @@ jobs: - name: Show Vagrant version run: VAGRANT_LOG=debug vagrant --version + - name: Install libvirt plugin + run: VAGRANT_LOG=debug vagrant plugin install vagrant-libvirt + vagrant-user: runs-on: self-hosted needs: vagrant-set-up steps: - name: Run vagrant user.yml - run: VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --playbook=user.yml --headless up + run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --playbook=user.yml --headless up - name: Destroy vagrant user.yml - run: timeout -k 60 -s 9 60 vagrant destroy -f || true + run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true if: always() - name: Destroy all virtualbox machines @@ -52,10 +55,10 @@ jobs: needs: vagrant-set-up steps: - name: Run vagrant common-desktop.yml - run: VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --headless up + run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --headless up - name: Destroy vagrant common-desktop.yml - run: timeout -k 60 -s 9 60 vagrant destroy -f || true + run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true if: always() - name: Destroy all virtualbox machines @@ -68,10 +71,10 @@ jobs: needs: vagrant-set-up steps: - name: Run vagrant common-minimal-desktop.yml - run: VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --playbook=common-minimal-desktop.yml --headless up + run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --playbook=common-minimal-desktop.yml --headless up - name: Destroy vagrant common-minimal-desktop.yml - run: timeout -k 60 -s 9 60 vagrant destroy -f || true + run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true if: always() - name: Destroy all virtualbox machines @@ -84,10 +87,10 @@ jobs: needs: vagrant-set-up steps: - name: Run vagrant user.yml - run: VAGRANT_LOG=debug vagrant --os=bento/ubuntu-24.04 --local --playbook=user.yml --headless up + run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=bento/ubuntu-24.04 --local --playbook=user.yml --headless up - name: Destroy vagrant user.yml - run: timeout -k 60 -s 9 60 vagrant destroy -f || true + run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true if: always() - name: Destroy all virtualbox machines @@ -100,12 +103,40 @@ jobs: needs: vagrant-set-up steps: - name: Run vagrant common-desktop.yml - run: VAGRANT_LOG=debug vagrant --os=bento/ubuntu-24.04 --local --headless up + run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=bento/ubuntu-24.04 --local --headless up - name: Destroy vagrant common-desktop.yml - run: timeout -k 60 -s 9 60 vagrant destroy -f || true + run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true if: always() - name: Destroy all virtualbox machines run: VBoxManage list vms | awk -F'"' '/.*ansible-playbooks.*/ {print $2}' | xargs -I {} VBoxManage unregistervm {} --delete if: always() + + vagrant-common-devserver-2404: + runs-on: self-hosted + + needs: vagrant-set-up + steps: + - name: Run vagrant common-devserver.yml + run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=bento/ubuntu-24.04 --local --headless up + + - name: Destroy vagrant common-devserver.yml + run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true + if: always() + + - name: Destroy all virtualbox machines + run: VBoxManage list vms | awk -F'"' '/.*ansible-playbooks.*/ {print $2}' | xargs -I {} VBoxManage unregistervm {} --delete + if: always() + + vagrant-common-devserver-2404-arm64: + runs-on: self-hosted + + needs: vagrant-set-up + steps: + - name: Run vagrant common-devserver.yml + run: VAGRANT_DEFAULT_PROVIDER=libvirt VAGRANT_LOG=debug vagrant --os=cloud-image/ubuntu-24.04 --local --headless up + + - name: Destroy vagrant common-devserver.yml + run: VAGRANT_DEFAULT_PROVIDER=libvirt timeout -k 60 -s 9 60 vagrant destroy -f || true + if: always() diff --git a/Vagrantfile b/Vagrantfile index fbeb3d1..af88caa 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -7,14 +7,20 @@ opts = GetoptLong.new( ["--local", GetoptLong::NO_ARGUMENT], ["--headless", GetoptLong::NO_ARGUMENT], ["--playbook", GetoptLong::OPTIONAL_ARGUMENT], + ["--architecture", GetoptLong::OPTIONAL_ARGUMENT], ["--os", GetoptLong::OPTIONAL_ARGUMENT], - ["-f", GetoptLong::OPTIONAL_ARGUMENT] + ["-f", GetoptLong::OPTIONAL_ARGUMENT], + # Pass arguments to actual vagrant, but they're not used here + ["--provider", GetoptLong::OPTIONAL_ARGUMENT], + ["--help", GetoptLong::OPTIONAL_ARGUMENT], + ["--debug", GetoptLong::OPTIONAL_ARGUMENT] ) local = false gui = true os = "ubuntu/focal64" playbook = "common-desktop.yml" +architecture = "amd64" opts.each do |opt, arg| case opt @@ -26,18 +32,27 @@ opts.each do |opt, arg| gui = false when "--playbook" playbook = arg + when "--architecture" + architecture = arg end end # Example: # * vagrant --os=ubuntu/jammy64 --playbook=user.yml --local --headless up # * vagrant --os=bento/ubuntu-24.04 --playbook=common-desktop.yml --local up +# * vagrant --os=cloud-image/ubuntu-24.04 --local --headless --architecture=arm64 up --provider libvirt # # Known problems: # * Sometimes disk fails to set up (systemd waits on disk uuid), `vagrant destroy` and try again in this case Vagrant.configure("2") do |config| + if architecture == "arm64" + config.vagrant.plugins = "vagrant-libvirt" + config.vm.box_architecture = architecture + end + config.vm.synced_folder ".", "/vagrant" + config.vm.box = os # Need to run `vagrant provision` explicitly for that to work @@ -46,10 +61,37 @@ Vagrant.configure("2") do |config| trigger.run = { :inline => "vagrant reload" } end + # https://vagrant-libvirt.github.io/vagrant-libvirt/configuration.html + # Currently libvirt is only used for arm64. However, to destroy arm machines + # even if the architecture argument is not passed, we need to set all the + # libvirt options anyway, in particular to make this fix work + # https://github.com/vagrant-libvirt/vagrant-libvirt/pull/1329/files + config.vm.provider "libvirt" do |libvirt| + # Give more resources, OOMs by default + libvirt.memory = 8000 + # Max 8 cores allowed for arm cpu + libvirt.cpus = [`nproc`.to_i, 8].min + libvirt.machine_type = "virt" + # https://libvirt.org/formatdomain.html + # In this mode, the cpu element describes the CPU that should be presented + # to the guest. This is the default when no mode attribute is specified. + # This mode makes it so that a persistent guest will see the same hardware + # no matter what host the guest is booted on. + libvirt.cpu_mode = "custom" + libvirt.cpu_model = "cortex-a57" + libvirt.driver = "qemu" + libvirt.machine_arch = "aarch64" + # Enable UEFI, refuses to work otherwise + libvirt.nvram = true + libvirt.loader = "/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd" + # Errors otherwise + libvirt.inputs = [] + end + config.vm.provider "virtualbox" do |vb| # Give more resources, OOMs by default vb.memory = 8000 - vb.cpus = 8 + vb.cpus = `nproc`.to_i # Make UI fast vb.gui = gui @@ -66,6 +108,8 @@ Vagrant.configure("2") do |config| config.vm.provision "shell", env: {}, inline: <<-SHELL set -uex + systemctl disable systemd-networkd.service + rm -f /etc/resolv.conf echo "nameserver 8.8.8.8" > /etc/resolv.conf @@ -117,6 +161,8 @@ Vagrant.configure("2") do |config| config.vm.provision "shell", env: {}, inline: <<-SHELL set -uex + systemctl disable systemd-networkd.service + rm -f /etc/resolv.conf echo "nameserver 8.8.8.8" > /etc/resolv.conf diff --git a/roles/libvirtd/handlers/main.yml b/roles/libvirtd/handlers/main.yml new file mode 100644 index 0000000..11f499f --- /dev/null +++ b/roles/libvirtd/handlers/main.yml @@ -0,0 +1,5 @@ +- name: libvirtd restart + systemd: + name: libvirtd + state: restarted + daemon_reload: yes diff --git a/roles/libvirtd/tasks/configs.yml b/roles/libvirtd/tasks/configs.yml new file mode 100644 index 0000000..d3bd1b9 --- /dev/null +++ b/roles/libvirtd/tasks/configs.yml @@ -0,0 +1,9 @@ +# Fix error similar to this: https://old.reddit.com/r/virtualization/comments/mjm1ow/virtmanager_error_when_creating_vm_unable_to/ +# TODO: figure out how to fix it correctly +- name: config disable apparmor for libvirt + lineinfile: + path: /etc/libvirt/qemu.conf + regexp: '.*security_driver.*' + line: 'security_driver = "none"' + notify: + - libvirtd restart diff --git a/roles/libvirtd/tasks/main.yml b/roles/libvirtd/tasks/main.yml index 679c2c7..1fbbe52 100644 --- a/roles/libvirtd/tasks/main.yml +++ b/roles/libvirtd/tasks/main.yml @@ -1,2 +1,3 @@ - import_tasks: packages.yml +- import_tasks: configs.yml - import_tasks: services.yml