first commit
This commit is contained in:
51
roles/proxmox_vm/tasks/main.yml
Normal file
51
roles/proxmox_vm/tasks/main.yml
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
- name: Get next available VMID
|
||||
community.general.proxmox_next_id:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
api_user: "{{ proxmox_api_user }}"
|
||||
api_token_id: "{{ proxmox_api_token_id }}"
|
||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
||||
register: next_vmid
|
||||
|
||||
- name: Clone VM from template
|
||||
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 }}"
|
||||
node: "{{ target_node }}"
|
||||
clone: "ubuntu24vm"
|
||||
name: "{{ vm_hostname }}"
|
||||
vmid: "{{ next_vmid.vmid }}"
|
||||
full: true
|
||||
storage: "local-lvm"
|
||||
timeout: 300
|
||||
register: cloned_vm
|
||||
|
||||
- name: Configure VM resources
|
||||
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 }}"
|
||||
node: "{{ target_node }}"
|
||||
vmid: "{{ next_vmid.vmid }}"
|
||||
cores: "{{ cpu_cores }}"
|
||||
memory: "{{ ram_gb | int * 1024 }}"
|
||||
net:
|
||||
net0: "virtio,bridge=vmbr0"
|
||||
update: true
|
||||
|
||||
- name: Start the VM
|
||||
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 }}"
|
||||
node: "{{ target_node }}"
|
||||
vmid: "{{ next_vmid.vmid }}"
|
||||
state: started
|
||||
|
||||
- name: Set VMID fact for later use
|
||||
ansible.builtin.set_fact:
|
||||
created_vmid: "{{ next_vmid.vmid }}"
|
||||
Reference in New Issue
Block a user