From e3d0be5df3a8a43b19da0bb814c8174048cfc79f Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 6 Jan 2022 19:22:14 +0100 Subject: split up vm/define into remove and create --- roles/vm/guest/create/defaults/main.yml | 5 ++ roles/vm/guest/create/tasks/main.yml | 28 +++++++ .../guest/create/templates/libvirt-domain.xml.j2 | 96 ++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 roles/vm/guest/create/defaults/main.yml create mode 100644 roles/vm/guest/create/tasks/main.yml create mode 100644 roles/vm/guest/create/templates/libvirt-domain.xml.j2 (limited to 'roles/vm/guest/create') diff --git a/roles/vm/guest/create/defaults/main.yml b/roles/vm/guest/create/defaults/main.yml new file mode 100644 index 00000000..8609c377 --- /dev/null +++ b/roles/vm/guest/create/defaults/main.yml @@ -0,0 +1,5 @@ +--- +vm_create_autostart: "{{ not vm_create_installer and install.vm.autostart | default(False) }}" +vm_create_start: yes + +vm_create_installer: no diff --git a/roles/vm/guest/create/tasks/main.yml b/roles/vm/guest/create/tasks/main.yml new file mode 100644 index 00000000..d9215b40 --- /dev/null +++ b/roles/vm/guest/create/tasks/main.yml @@ -0,0 +1,28 @@ +--- +- name: define vm + delegate_to: "{{ vm_host.name }}" + virt: + command: define + xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}" + +- name: start new vm + when: vm_create_start | bool + delegate_to: "{{ vm_host.name }}" + block: + - name: start vm + virt: + name: "{{ inventory_hostname }}" + state: running + + - name: wait for VM to start + wait_for_virt: + name: "{{ inventory_hostname }}" + states: running + timeout: 10 + +- name: mark vm as autostarted + delegate_to: "{{ vm_host.name }}" + virt: + name: "{{ inventory_hostname }}" + autostart: "{{ vm_create_autostart }}" + command: info ## virt module needs either command or state diff --git a/roles/vm/guest/create/templates/libvirt-domain.xml.j2 b/roles/vm/guest/create/templates/libvirt-domain.xml.j2 new file mode 100644 index 00000000..96b12a74 --- /dev/null +++ b/roles/vm/guest/create/templates/libvirt-domain.xml.j2 @@ -0,0 +1,96 @@ + + {{ inventory_hostname }} + {{ ((install.vm.memory | human_to_bytes) / 1024) | int }} + {{ ((install.vm.memory | human_to_bytes) / 1024) | int }} + {{ install.vm.numcpus }} + + hvm +{% if vm_create_installer %} +{% if install_distro == 'debian' or install_distro == 'ubuntu' %} + {{ installer_tmpdir }}/linux + {{ installer_tmpdir }}/initrd.gz + console=ttyS0,115200n8 auto + +{% elif install_distro == 'openbsd' %} + +{% endif %} +{% else %} + +{% endif %} + + + + + + + + destroy +{% if vm_create_installer %} + destroy + destroy +{% else %} + restart + restart +{% endif %} + + /usr/bin/kvm + + + + + /dev/random + + +{% if vm_create_installer and install_distro == 'openbsd' %} + + + + + + + +{% endif %} +{% if install.disks %} +{% if 'scsi' in install.disks %} + +{% endif %} +{% for bus in ['virtio', 'scsi'] %} +{% for device, src in (install.disks[bus] | default({})).items() %} + + +{% if src.type == 'lvm' %} + +{% elif src.type == 'zfs' %} + +{% elif src.type == 'blockdev' %} + +{% elif src.type == 'image' %} + +{% endif %} + + +{% endfor %} +{% endfor %} + +{% endif %} +{% if install.interfaces %} +{% for if in install.interfaces %} + +{% if 'mac' in if %} + +{% endif %} + + +
+ +{% endfor %} + +{% endif %} + + + + + + + + -- cgit v1.2.3