You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
5.8 KiB
YAML

---
- name: Proxmox - Check if VM already exists
community.general.proxmox_vm_info:
api_host: "{{ create_vm_proxmox_host }}"
api_user: "{{ create_vm_proxmox_user }}"
api_password: "{{ create_vm_proxmox_password }}"
vmid: "{{ create_vm_proxmox_vmid }}"
register: create_vm_proxmox_check_if_vm_exists
when: create_vm_proxmox_recreate_vm | bool
delegate_to: localhost
- name: Proxmox - Delete VM if it already exists
community.general.proxmox_kvm:
api_host: "{{ create_vm_proxmox_host }}"
api_user: "{{ create_vm_proxmox_user }}"
api_password: "{{ create_vm_proxmox_password }}"
vmid: "{{ create_vm_proxmox_vmid }}"
name: "{{ create_vm_proxmox_name }}"
state: absent
force: true
timeout: 30
when:
- create_vm_proxmox_check_if_vm_exists.proxmox_vms is defined
- create_vm_proxmox_check_if_vm_exists.proxmox_vms | length > 0
- create_vm_proxmox_recreate_vm | bool
delegate_to: localhost
- name: Proxmox - Check if VM already exists
community.general.proxmox_vm_info:
api_host: "{{ create_vm_proxmox_host }}"
api_user: "{{ create_vm_proxmox_user }}"
api_password: "{{ create_vm_proxmox_password }}"
vmid: "{{ create_vm_proxmox_vmid }}"
register: create_vm_proxmox_check_if_vm_exists
delegate_to: localhost
- name: Proxmox - Clone VM in Proxmox
community.general.proxmox_kvm:
api_host: "{{ create_vm_proxmox_host }}"
api_user: "{{ create_vm_proxmox_user }}"
api_password: "{{ create_vm_proxmox_password }}"
node: "{{ create_vm_proxmox_host }}"
newid: "{{ create_vm_proxmox_vmid }}"
name: "{{ create_vm_proxmox_name }}"
clone: "{{ create_vm_proxmox_source_vm }}"
net: "{{ create_vm_proxmox_net | default(omit) }}"
when: create_vm_proxmox_check_if_vm_exists.proxmox_vms | length == 0
register: create_vm_proxmox_clone_vm
delegate_to: localhost
- name: Proxmox - Update VM hardware
community.general.proxmox_kvm:
api_host: "{{ create_vm_proxmox_host }}"
api_user: "{{ create_vm_proxmox_user }}"
api_password: "{{ create_vm_proxmox_password }}"
vmid: "{{ create_vm_proxmox_vmid }}"
node: "{{ create_vm_proxmox_host }}"
vcpus: "{{ create_vm_proxmox_numb_cpus | default(omit) }}"
cores: "{{ create_vm_proxmox_numb_cores | default(omit) }}"
memory: "{{ create_vm_proxmox_memory_mb | default(omit) }}"
update: true
delegate_to: localhost
when:
- create_vm_proxmox_numb_cpus is defined or
create_vm_proxmox_numb_cores is defined or
create_vm_proxmox_memory_mb is defined
- name: Proxmox - Manage virtual disks for virtual machine
community.general.proxmox_disk:
api_host: "{{ create_vm_proxmox_host }}"
api_user: "{{ create_vm_proxmox_user }}"
api_password: "{{ create_vm_proxmox_password }}"
vmid: "{{ create_vm_proxmox_vmid }}"
disk: "{{ item.key }}"
format: "{{ item.value.format | default(omit) }}"
storage: "{{ item.value.storage | default(omit) }}"
size: "{{ item.value.size | default(omit) }}"
state: "{{ item.value.state | default(omit) }}"
loop: "{{ create_vm_proxmox_vm_disks | dict2items }}"
when: create_vm_proxmox_vm_disks is defined
delegate_to: localhost
- name: Proxmox - Add cloud-init drive
community.general.proxmox_kvm:
api_host: "{{ create_vm_proxmox_host }}"
api_user: "{{ create_vm_proxmox_user }}"
api_password: "{{ create_vm_proxmox_password }}"
node: "{{ create_vm_proxmox_host }}"
vmid: "{{ create_vm_proxmox_vmid }}"
name: "{{ create_vm_proxmox_name }}"
update: true
update_unsafe: true
ide:
ide2: "{{ create_vm_proxmox_cloudinit_storage_pool }}:cloudinit,format=raw"
when: create_vm_proxmox_add_cloudinit_drive | bool
delegate_to: localhost
- name: Proxmox - Add cloud-init settings
community.general.proxmox_kvm:
api_host: "{{ create_vm_proxmox_host }}"
api_user: "{{ create_vm_proxmox_user }}"
api_password: "{{ create_vm_proxmox_password }}"
node: "{{ create_vm_proxmox_host }}"
vmid: "{{ create_vm_proxmox_vmid }}"
name: "{{ create_vm_proxmox_name }}"
update: true
update_unsafe: true
ciuser: "{{ create_vm_proxmox_cloudinit_user }}"
cipassword: "{{ create_vm_proxmox_cloudinit_user }}"
sshkeys: "{{ create_vm_proxmox_cloudinit_sshkeys }}"
ipconfig: "{{ create_vm_proxmox_cloudinit_ipconfig }}"
nameservers: "{{ create_vm_proxmox_cloudinit_nameservers }}"
searchdomains: "{{ create_vm_proxmox_cloudinit_searchdomains }}"
when:
- create_vm_proxmox_check_if_vm_exists.proxmox_vms | length == 0
- create_vm_proxmox_configure_cloudinit | bool
delegate_to: localhost
- name: Proxmox - Enable QEMU guest agent for VM
community.general.proxmox_kvm:
api_host: "{{ create_vm_proxmox_host }}"
api_user: "{{ create_vm_proxmox_user }}"
api_password: "{{ create_vm_proxmox_password }}"
node: "{{ create_vm_proxmox_host }}"
vmid: "{{ create_vm_proxmox_vmid }}"
name: "{{ create_vm_proxmox_name }}"
agent: true
update: true
when: create_vm_proxmox_enable_guest_agent | bool
delegate_to: localhost
- name: Proxmox - Set VM to autostart
community.general.proxmox_kvm:
api_host: "{{ create_vm_proxmox_host }}"
api_user: "{{ create_vm_proxmox_user }}"
api_password: "{{ create_vm_proxmox_password }}"
node: "{{ create_vm_proxmox_host }}"
vmid: "{{ create_vm_proxmox_vmid }}"
name: "{{ create_vm_proxmox_name }}"
onboot: true
update: true
when: create_vm_proxmox_start_vm_onboot | bool
delegate_to: localhost
- name: Proxmox - Start VM
community.general.proxmox_kvm:
api_host: "{{ create_vm_proxmox_host }}"
api_user: "{{ create_vm_proxmox_user }}"
api_password: "{{ create_vm_proxmox_password }}"
node: "{{ create_vm_proxmox_host }}"
vmid: "{{ create_vm_proxmox_vmid }}"
name: "{{ create_vm_proxmox_name }}"
state: started
when: create_vm_proxmox_start_vm
delegate_to: localhost
...