Changed getting vmid logic

This commit is contained in:
2026-02-02 13:50:42 -05:00
parent 9cdef0a9e3
commit c8678716bf
4 changed files with 34 additions and 24 deletions

View File

@@ -51,7 +51,7 @@ proxmox-template-clone/
### Ansible Collections ### Ansible Collections
```yaml ```yaml
- community.general >= 9.1.0 - community.general >= 8.0.0
- ansible.posix >= 1.5.0 - ansible.posix >= 1.5.0
``` ```

View File

@@ -1,6 +1,6 @@
--- ---
collections: collections:
- name: community.general - name: community.general
version: ">=9.1.0" version: ">=8.0.0"
- name: ansible.posix - name: ansible.posix
version: ">=1.5.0" version: ">=1.5.0"

View File

@@ -1,11 +1,16 @@
--- ---
- name: Get next available VMID - name: Get next available VMID from Proxmox API
community.general.proxmox_next_id: ansible.builtin.uri:
api_host: "{{ proxmox_api_host }}" url: "https://{{ proxmox_api_host }}:8006/api2/json/cluster/nextid"
api_user: "{{ proxmox_api_user }}" method: GET
api_token_id: "{{ proxmox_api_token_id }}" headers:
api_token_secret: "{{ proxmox_api_token_secret }}" Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
register: next_vmid validate_certs: false
register: nextid_response
- name: Set VMID fact
ansible.builtin.set_fact:
next_vmid: "{{ nextid_response.json.data }}"
- name: Clone LXC from template - name: Clone LXC from template
community.general.proxmox: community.general.proxmox:
@@ -16,7 +21,7 @@
node: "{{ target_node }}" node: "{{ target_node }}"
clone: "ubuntu24lxc" clone: "ubuntu24lxc"
hostname: "{{ vm_hostname }}" hostname: "{{ vm_hostname }}"
vmid: "{{ next_vmid.vmid }}" vmid: "{{ next_vmid }}"
full: true full: true
storage: "local-lvm" storage: "local-lvm"
timeout: 300 timeout: 300
@@ -29,7 +34,7 @@
api_token_id: "{{ proxmox_api_token_id }}" api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token_secret }}" api_token_secret: "{{ proxmox_api_token_secret }}"
node: "{{ target_node }}" node: "{{ target_node }}"
vmid: "{{ next_vmid.vmid }}" vmid: "{{ next_vmid }}"
cores: "{{ cpu_cores }}" cores: "{{ cpu_cores }}"
memory: "{{ ram_gb | int * 1024 }}" memory: "{{ ram_gb | int * 1024 }}"
netif: netif:
@@ -43,9 +48,9 @@
api_token_id: "{{ proxmox_api_token_id }}" api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token_secret }}" api_token_secret: "{{ proxmox_api_token_secret }}"
node: "{{ target_node }}" node: "{{ target_node }}"
vmid: "{{ next_vmid.vmid }}" vmid: "{{ next_vmid }}"
state: started state: started
- name: Set VMID fact for later use - name: Set VMID fact for later use
ansible.builtin.set_fact: ansible.builtin.set_fact:
created_vmid: "{{ next_vmid.vmid }}" created_vmid: "{{ next_vmid }}"

View File

@@ -1,11 +1,16 @@
--- ---
- name: Get next available VMID - name: Get next available VMID from Proxmox API
community.general.proxmox_next_id: ansible.builtin.uri:
api_host: "{{ proxmox_api_host }}" url: "https://{{ proxmox_api_host }}:8006/api2/json/cluster/nextid"
api_user: "{{ proxmox_api_user }}" method: GET
api_token_id: "{{ proxmox_api_token_id }}" headers:
api_token_secret: "{{ proxmox_api_token_secret }}" Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
register: next_vmid validate_certs: false
register: nextid_response
- name: Set VMID fact
ansible.builtin.set_fact:
next_vmid: "{{ nextid_response.json.data }}"
- name: Clone VM from template - name: Clone VM from template
community.general.proxmox_kvm: community.general.proxmox_kvm:
@@ -16,7 +21,7 @@
node: "{{ target_node }}" node: "{{ target_node }}"
clone: "ubuntu24vm" clone: "ubuntu24vm"
name: "{{ vm_hostname }}" name: "{{ vm_hostname }}"
vmid: "{{ next_vmid.vmid }}" newid: "{{ next_vmid }}"
full: true full: true
storage: "local-lvm" storage: "local-lvm"
timeout: 300 timeout: 300
@@ -29,7 +34,7 @@
api_token_id: "{{ proxmox_api_token_id }}" api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token_secret }}" api_token_secret: "{{ proxmox_api_token_secret }}"
node: "{{ target_node }}" node: "{{ target_node }}"
vmid: "{{ next_vmid.vmid }}" vmid: "{{ next_vmid }}"
cores: "{{ cpu_cores }}" cores: "{{ cpu_cores }}"
memory: "{{ ram_gb | int * 1024 }}" memory: "{{ ram_gb | int * 1024 }}"
net: net:
@@ -43,9 +48,9 @@
api_token_id: "{{ proxmox_api_token_id }}" api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token_secret }}" api_token_secret: "{{ proxmox_api_token_secret }}"
node: "{{ target_node }}" node: "{{ target_node }}"
vmid: "{{ next_vmid.vmid }}" vmid: "{{ next_vmid }}"
state: started state: started
- name: Set VMID fact for later use - name: Set VMID fact for later use
ansible.builtin.set_fact: ansible.builtin.set_fact:
created_vmid: "{{ next_vmid.vmid }}" created_vmid: "{{ next_vmid }}"