--- # tasks file for proxmox - name: Build disks list ansible.builtin.set_fact: proxmox_instance_disks: "{{ proxmox_instance_disks + specific }}" when: specific | length > 0 loop: "{{ lookup('ansible.builtin.varnames', '^proxmox_instance_disks_.+', wantlist=True) }}" vars: specific: "{{ lookup('ansible.builtin.vars', item, default='') }}" - name: Configure disks community.general.proxmox_disk: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_token_id: "{{ proxmox_api_token_id }}" api_token_secret: "{{ proxmox_api_token_secret }}" aio: "{{ item.aio | default(omit) }}" backup: "{{ item.backup | default(omit) }}" cache: "{{ item.cache | default(omit) }}" disk: "{{ item.disk }}" iothread: "{{ item.iothread | default(omit) }}" mbps: "{{ item.mbps | default(omit) }}" name: "{{ inventory_hostname }}" storage: "{{ item.storage }}" size: "{{ item.size }}" state: present vmid: "{{ proxmox_instance_vmid }}" loop: "{{ proxmox_instance_disks }}" loop_control: label: "{{ item.disk }}" index_var: disk_number delegate_to: "{{ proxmox_delegate_to | default(omit) }}" - name: Get instance informations community.general.proxmox_vm_info: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_token_id: "{{ proxmox_api_token_id }}" api_token_secret: "{{ proxmox_api_token_secret }}" config: current name: "{{ inventory_hostname }}" vmid: "{{ proxmox_instance_vmid }}" delegate_to: "{{ proxmox_delegate_to | default(omit) }}" register: instance_current_infos - name: Grow disk size community.general.proxmox_disk: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_token_id: "{{ proxmox_api_token_id }}" api_token_secret: "{{ proxmox_api_token_secret }}" aio: "{{ item.aio | default(omit) }}" backup: "{{ item.backup | default(omit) }}" cache: "{{ item.cache | default(omit) }}" disk: "{{ item.disk }}" iothread: "{{ item.iothread | default(omit) }}" mbps: "{{ item.mbps | default(omit) }}" name: "{{ inventory_hostname }}" storage: "{{ item.storage }}" size: "{{ item.size }}G" state: resized vmid: "{{ proxmox_instance_vmid }}" when: - proxmox_instance_disks | length > 0 - instance_current_infos.proxmox_vms | length > 0 - formated_size not in instance_current_infos.proxmox_vms[0].config[item.disk] loop: "{{ proxmox_instance_disks }}" loop_control: label: "{{ item.disk }}" index_var: disk_number delegate_to: "{{ proxmox_delegate_to | default(omit) }}" vars: formated_size: "size={{ item.size }}G" - name: Reconfigure instance community.general.proxmox_kvm: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_token_id: "{{ proxmox_api_token_id }}" api_token_secret: "{{ proxmox_api_token_secret }}" agent: "enabled=1,fstrim_cloned_disks=1" autostart: "{{ proxmox_instance_autostart }}" cores: "{{ proxmox_instance_cores }}" cpu: "{{ proxmox_instance_cpu }}" hotplug: "{{ proxmox_instance_hotplug | join(',') }}" ipconfig: "{{ proxmox_instance_ipconfig }}" memory: "{{ proxmox_instance_memory }}" name: "{{ inventory_hostname }}" nameservers: "{{ proxmox_instance_cloudinit_nameservers }}" node: "{{ proxmox_instance_node }}" numa_enabled: "{{ proxmox_instance_numa }}" onboot: "{{ proxmox_instance_onboot }}" protection: "{{ proxmox_instance_protection }}" tablet: false vmid: "{{ proxmox_instance_vmid }}" update: true update_unsafe: true delegate_to: "{{ proxmox_delegate_to | default(omit) }}" - name: Get changed information about the instance community.general.proxmox_vm_info: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_token_id: "{{ proxmox_api_token_id }}" api_token_secret: "{{ proxmox_api_token_secret }}" config: pending name: "{{ inventory_hostname }}" vmid: "{{ proxmox_instance_vmid }}" node: "{{ proxmox_instance_node }}" when: not create_instance.changed delegate_to: "{{ proxmox_delegate_to | default(omit) }}" register: instance_pending_infos - name: Reboot the instance community.general.proxmox_kvm: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_token_id: "{{ proxmox_api_token_id }}" api_token_secret: "{{ proxmox_api_token_secret }}" name: "{{ inventory_hostname }}" node: "{{ proxmox_instance_node }}" state: restarted timeout: 300 when: - proxmox_reboot_instance - not create_instance.changed - instance_current_infos.proxmox_vms[0].config != instance_pending_infos.proxmox_vms[0].config delegate_to: "{{ proxmox_delegate_to | default(omit) }}" notify: Attendre que le port SSH soit ouvert register: rebooted - name: Flush handlers ansible.builtin.meta: flush_handlers - name: Ensure instance is started community.general.proxmox_kvm: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_token_id: "{{ proxmox_api_token_id }}" api_token_secret: "{{ proxmox_api_token_secret }}" name: "{{ inventory_hostname }}" node: "{{ proxmox_instance_node }}" state: started delegate_to: "{{ proxmox_delegate_to | default(omit) }}" notify: Attendre que le port SSH soit ouvert - name: Flush handlers ansible.builtin.meta: flush_handlers