46 lines
1.2 KiB
YAML
46 lines
1.2 KiB
YAML
---
|
|
- name: Create VM disk
|
|
delegate_to: localhost
|
|
ansible.builtin.command:
|
|
argv:
|
|
- qemu-img
|
|
- create
|
|
- -f
|
|
- qcow2
|
|
- "{{ virtualization_libvirt_disk_path }}"
|
|
- "{{ vm_size }}G"
|
|
creates: "{{ virtualization_libvirt_disk_path }}"
|
|
|
|
- name: Render cloud config templates
|
|
delegate_to: localhost
|
|
ansible.builtin.template:
|
|
src: "{{ item.src }}"
|
|
dest: /tmp/{{ item.dest_prefix }}-{{ hostname }}.yml
|
|
mode: '0644'
|
|
loop:
|
|
- {src: cloud-user-data.yml.j2, dest_prefix: cloud-user-data}
|
|
- {src: cloud-network-config.yml.j2, dest_prefix: cloud-network-config}
|
|
|
|
- name: Create cloud-init disk
|
|
delegate_to: localhost
|
|
ansible.builtin.command:
|
|
argv:
|
|
- cloud-localds
|
|
- "{{ virtualization_libvirt_cloudinit_path }}"
|
|
- "/tmp/cloud-user-data-{{ hostname }}.yml"
|
|
- -N
|
|
- "/tmp/cloud-network-config-{{ hostname }}.yml"
|
|
creates: "{{ virtualization_libvirt_cloudinit_path }}"
|
|
|
|
- name: Create VM using libvirt
|
|
delegate_to: localhost
|
|
community.libvirt.virt:
|
|
command: define
|
|
xml: "{{ lookup('template', 'vm.xml.j2') }}"
|
|
|
|
- name: Start vm
|
|
delegate_to: localhost
|
|
community.libvirt.virt:
|
|
name: "{{ hostname }}"
|
|
state: running
|