From 4be4474884f8bbfe44f7ad35aa539f4a15aaecc4 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Wed, 7 Jun 2023 10:51:14 -0400 Subject: [PATCH] ansible: Manage libvirt on CI 'hosts' Change-Id: I970fe82d65de551ff51568f1ab72c5331cad3e57 --- .gitignore | 2 + automation/ansible/README.md | 29 ++++ automation/ansible/hosts.yml | 1 + .../libvirt/files/rootnode-autoinstall.yml | 85 ++++++++++ .../ansible/roles/libvirt/files/user-data | 1 + .../ansible/roles/libvirt/tasks/main.yml | 33 ++++ .../libvirt/templates/vm_template.xml.j2 | 155 ++++++++++++++++++ .../ansible/roles/libvirt/vars/main.yml | 15 ++ 8 files changed, 321 insertions(+) create mode 100644 automation/ansible/roles/libvirt/files/rootnode-autoinstall.yml create mode 120000 automation/ansible/roles/libvirt/files/user-data create mode 100644 automation/ansible/roles/libvirt/tasks/main.yml create mode 100644 automation/ansible/roles/libvirt/templates/vm_template.xml.j2 create mode 100644 automation/ansible/roles/libvirt/vars/main.yml diff --git a/.gitignore b/.gitignore index a4670d6..e64f1a9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ *.retry lava/pdudaemon/venv/ lava/pdudaemon/pdudaemon.db +automation/ansible/roles/libvirt/files/meta-data +automation/ansible/roles/libvirt/files/vendor-data \ No newline at end of file diff --git a/automation/ansible/README.md b/automation/ansible/README.md index 1a6c651..0965062 100644 --- a/automation/ansible/README.md +++ b/automation/ansible/README.md @@ -38,3 +38,32 @@ ansible-playbook -i hosts [-l SUBSET] site.yaml 1. Configure either SSH or WinRM connection: see https://docs.ansible.com/ansible/latest/os_guide/windows_setup.html 2. For arm64 hosts: * Install the necessary optional features (eg. OpenSSH, Hyper-V) since Windows RSAT isn't available on Arm64 yet + +## CI 'rootnode' + +1. Add an entry to the `vms` variable in the host vars for a libvirt host + * See the defaults and details in `roles/libvirt/vars/main.yml` and `roles/libvirt/tasks/main.yml` + * Make sure to set the `cdrom` key to the path of ISO for the installer +2. Run the playbook, eg. `ansible-playbook -i hosts -l cloud07.internal.efficios.com site.yml` + * The VM should be created and started +3. Once the VM is installed take a snapshot so that Jenkins may revert to the original state + +### Ubuntu auto-installer + +1. Note your IP address +2. Switch to the directory with the user-data files: `cd roles/libvirt/files` +3. Write out the instance-specific metadata, eg. + +``` +cat > meta-data < + {{ vm.name }} + {% if 'uuid' in vm %} + {{ vm.uuid }} + {% endif %} + {{ vm.memory }} + {{ vm.vcpu }} + + hvm + + + + + + + + + + + + + + destroy + restart + destroy + + + + + + /usr/bin/qemu-system-x86_64 + + + + {% if 'cdrom' in vm %} + + {% endif %} + +
+ + + {% if 'disk' in vm %} + + + + +
+ + + {% endif %} + +
+ + + +
+ + + +
+ + + +
+ + +
+ + +
+ + + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + +
+ + + + + +
+ + + + + + + + + + + +
+ + + +
+ + +
+ + + + + + +