install qemu guest agent on deployed vms

This commit is contained in:
2023-06-10 01:16:43 +02:00
parent 9d9d960425
commit 7d16eaf2cc
2 changed files with 46 additions and 9 deletions

View File

@@ -1,2 +1,2 @@
[vms] [vms]
test-vm vm_memory="2048" vm_cores="2" vm_ip_address="ip=10.11.12.88/24,gw=10.11.12.254" vm_root_disk_size="+20G" test-vm vm_memory="2048" vm_cores="2" vm_ip_address="ip=10.11.12.88/24,gw=10.11.12.254" resize_root_disk_size="+20G"

View File

@@ -1,5 +1,5 @@
--- ---
- name: create VM from template - name: Create VM from template, update the ip and hardware, resize the disk,
hosts: all hosts: all
gather_facts: false gather_facts: false
vars_files: vars_files:
@@ -20,11 +20,6 @@
register: vm_created register: vm_created
delegate_to: localhost delegate_to: localhost
# Display new VM details
- debug:
var: vm_created
delegate_to: localhost
- name: Update VM configuration - name: Update VM configuration
community.general.proxmox_kvm: community.general.proxmox_kvm:
api_host: "{{ pve_host }}" api_host: "{{ pve_host }}"
@@ -47,6 +42,48 @@
name: "{{ inventory_hostname }}" name: "{{ inventory_hostname }}"
disk: scsi0 disk: scsi0
backup: false backup: false
size: "{{ vm_root_disk_size }}" size: "{{ resize_root_disk_size }}"
state: resized state: resized
delegate_to: localhost delegate_to: localhost
- name: Start the VM
community.general.proxmox_kvm:
api_host: "{{ pve_host }}"
api_user: "{{ pve_user }}"
api_password: "{{ pve_password }}"
name: "{{ inventory_hostname }}"
node: "{{ node }}"
state: started
delegate_to: localhost
- name: Wait 3 minutes for VM to start and install latest updates
ansible.builtin.wait_for:
timeout: 180
delegate_to: localhost
- name: Extract VM IP with regex
set_fact:
vm_ip: "{{ vm_ip_address | regex_replace('ip=(\\d+\\.\\d+\\.\\d+\\.\\d+)/.*', '\\1') }}"
delegate_to: localhost
- name: Get information about the VM
ansible.builtin.setup:
delegate_to: "{{ vm_ip }}"
become: true
- name: Install Quemu Guest Agent if virtualization type is kvm
ansible.builtin.apt:
update_cache: true
name: qemu-guest-agent
state: latest
when: ansible_virtualization_type == 'kvm'
delegate_to: "{{ vm_ip }}"
become: true
- name: Enable QEMU Guest Agent
ansible.builtin.systemd:
name: qemu-guest-agent
enabled: true
when: ansible_virtualization_type == 'kvm'
delegate_to: "{{ vm_ip }}"
become: true