fix logic

This commit is contained in:
2025-09-23 18:26:13 -05:00
parent 1272fa3cb3
commit e7f8fd2ccd
4 changed files with 56 additions and 5 deletions

View File

@@ -13,8 +13,14 @@ proxmox_clone_node: "fantasyland"
# Templates are named in the following format (all lower case): <OS Distribution>-<OS Version>-<VM Size> # Templates are named in the following format (all lower case): <OS Distribution>-<OS Version>-<VM Size>
# Current OS offerings are: # Current OS offerings are:
# - Ubuntu (24.04) # - Ubuntu
# - Fedora (42) # - 24.04
# - Fedora
# - 42
vm_os_distribution: "ubuntu"
vm_os_version: "24.04"
# Current VM sizes are: # Current VM sizes are:
# - Small: 2 cores, 2GB memory, 8 GiB virtual disk # - Small: 2 cores, 2GB memory, 8 GiB virtual disk
# - Medium: 2 cores, 4GB memory, 16 GiB virtual disk # - Medium: 2 cores, 4GB memory, 16 GiB virtual disk
@@ -22,7 +28,7 @@ proxmox_clone_node: "fantasyland"
# - Large Plus: 4 cores, 4GB memory, 48 GiB virtual disk # - Large Plus: 4 cores, 4GB memory, 48 GiB virtual disk
# - Xlarge: 4 cores, 8GB memory, 64 GiB virtual disk # - Xlarge: 4 cores, 8GB memory, 64 GiB virtual disk
vm_clone_source: "ubuntu-24.04-large-plus" vm_size: "large-plus"
# Proxmox storage target. # Proxmox storage target.
@@ -47,4 +53,5 @@ ip_address: 10.1.71.53
# --- # ---
vm_clone_source: "{{ vm_os_distribution }}-{{ vm_os_version }}-{{ vm_size }}"
hostname: "{{ inventory_hostname }}.{{ base_domain }}" # Change variable to fqdn hostname: "{{ inventory_hostname }}.{{ base_domain }}" # Change variable to fqdn

View File

@@ -3,8 +3,13 @@
hosts: all hosts: all
gather_facts: false gather_facts: false
- name: Proxmox Clone VM Playbook - name: Proxmox Clone Ubuntu VM Playbook
ansible.builtin.import_playbook: proxmox_clone_vm.yml ansible.builtin.import_playbook: proxmox_clone_ubuntu_vm.yml
when: vm_os_distribution == "ubuntu" and platform == "proxmox"
- name: Proxmox Clone Fedora VM Playbook
ansible.builtin.import_playbook: proxmox_clone_fedora_vm.yml
when: vm_os_distribution == "fedora" and platform == "proxmox"
# - name: DNS Playbook # - name: DNS Playbook
# ansible.builtin.import_playbook: add_dns_entry.yml # ansible.builtin.import_playbook: add_dns_entry.yml

View File

@@ -0,0 +1,39 @@
---
- name: Create VM ID from IP address for Proxmox hosts
hosts: all
gather_facts: false
tasks:
- name: Create Proxmox VMs
delegate_to: "localhost"
when: platform is defined and platform == "proxmox"
block:
- name: Create VM ID from IP address
ansible.builtin.set_fact:
vm_id: "{{ ip_address.split('.')[-2] }}{{ '%03d' % (ip_address.split('.')[-1] | int) }}"
- name: Clone VM with source vmid and target newid and raw format
community.proxmox.proxmox_kvm:
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
clone: "{{ vm_clone_source }}"
newid: "{{ vm_id }}"
name: "{{ inventory_hostname }}"
node: "{{ proxmox_clone_node }}"
storage: "{{ vm_storage }}"
format: qcow2 # raw
timeout: 600
ipconfig:
ipconfig0: 'ip=dhcp'
# - name: Add VM to HA group
# community.proxmox.proxmox_cluster_ha_resources:
# api_user: "{{ proxmox_user }}"
# api_password: "{{ proxmox_password }}"
# api_host: "{{ proxmox_host }}"
# name: vm:"{{ vm_id }}"
# state: "present"
# group: "{{ ha_group }}"
# max_relocate: 2
# max_restart: 2