ansible/roles/kvm_installvm/tasks/main.yml

35 lines
838 B
YAML

---
- name: Get VMs list
community.libvirt.virt:
command: list_vms
register: existing_vms
changed_when: no
- name: Create VM if not exists
block:
- name: Upload base image archiv to core's tmp directory
copy:
src: "{{ vm_base_image_archiv }}"
dest: "/home/core/tmp/"
owner: libvirt-qemu
group: kvm
mode: "0600"
- name: Gunzip base image in core's tmp directory
shell:
cmd: "/usr/bin/gunzip /home/core/tmp/{{ vm_base_image_archiv }}"
- name: Copy unarchived base image to /var/lib/libvirt/images and rename to $vm_name
copy:
src: "/home/core/tmp/{{ vm_base_image }}"
dest: "{{ libvirt_pool_dir }}/{{ vm_name }}"
remote_src: "yes"
owner: libvirt-qemu
group: kvm
mode: "0600"
when: "vm_name not in existing_vms.list_vms"
...