Updated to use cloud-init images
This commit is contained in:
+41
-8
@@ -26,20 +26,53 @@
|
||||
remote_src: yes
|
||||
mode: 0660
|
||||
register: copy_results
|
||||
- name: Define vm
|
||||
community.libvirt.virt:
|
||||
command: define
|
||||
xml: "{{ lookup('template', 'vm-template.xml.j2') }}"
|
||||
|
||||
- name: Generate cloud-init user-data from template
|
||||
delegate_to: localhost
|
||||
ansible.builtin.copy:
|
||||
src: files/leander.pub
|
||||
dest: /tmp/ansible_cloudinit_ssh.pub
|
||||
|
||||
- name: Generate cloud-init user-data from template
|
||||
delegate_to: localhost
|
||||
ansible.builtin.template:
|
||||
src: cloud-init.yml.j2
|
||||
dest: /tmp/ansible_cloudinit_userdata.config
|
||||
|
||||
- name: Copy network-config from file
|
||||
delegate_to: localhost
|
||||
ansible.builtin.template:
|
||||
src: templates/cloud-init-network.yml.j2
|
||||
dest: /tmp/ansible_cloudinit_network.config
|
||||
|
||||
- name: Configure the image
|
||||
command: |
|
||||
virt-customize -a {{ libvirt_pool_dir }}/{{ vm_name }}.qcow2 \
|
||||
--hostname {{ vm_name }} \
|
||||
--password {{ vm_user }}:password:{{ vm_pass }} \
|
||||
--root-password password:{{ root_passwd }} \
|
||||
--firstboot-command '/usr/bin/ssh-keygen -A'
|
||||
when: copy_results is changed
|
||||
|
||||
when: "vm_name not in existing_vms.list_vms"
|
||||
|
||||
|
||||
- name: Install the vm via virt-install
|
||||
ansible.builtin.command: |
|
||||
virt-install \
|
||||
--name "{{ vm_name }}" \
|
||||
--boot uefi \
|
||||
--machine q35 \
|
||||
--memory "{{ vm_ram_mb }}" \
|
||||
--vcpus "{{ vm_vcpus }}" \
|
||||
--disk "path={{ vm_pool_dir }}/{{ vm_name }}.qcow2" \
|
||||
--import \
|
||||
--os-variant "debian11" \
|
||||
--network "network={{ vm_net }},model=virtio,driver.iommu=on" \
|
||||
--rng /dev/urandom,driver.iommu=on \
|
||||
--memballoon driver.iommu=on \
|
||||
--virt-type kvm \
|
||||
--graphics vnc \
|
||||
--noautoconsole \
|
||||
--cloud-init user-data=/tmp/ansible_cloudinit_userdata.config,network-config=/tmp/ansible_cloudinit_network.config
|
||||
--noreboot \
|
||||
--qemu-commandline="-smbios type=1,serial=ds=nocloud;h={{ vm_name }}"
|
||||
|
||||
- name: Ensure VM is started
|
||||
community.libvirt.virt:
|
||||
|
||||
Reference in New Issue
Block a user