fix logic
This commit is contained in:
@@ -13,8 +13,14 @@ proxmox_clone_node: "fantasyland"
|
||||
|
||||
# Templates are named in the following format (all lower case): <OS Distribution>-<OS Version>-<VM Size>
|
||||
# Current OS offerings are:
|
||||
# - Ubuntu (24.04)
|
||||
# - Fedora (42)
|
||||
# - Ubuntu
|
||||
# - 24.04
|
||||
# - Fedora
|
||||
# - 42
|
||||
|
||||
vm_os_distribution: "ubuntu"
|
||||
vm_os_version: "24.04"
|
||||
|
||||
# Current VM sizes are:
|
||||
# - Small: 2 cores, 2GB memory, 8 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
|
||||
# - Xlarge: 4 cores, 8GB memory, 64 GiB virtual disk
|
||||
|
||||
vm_clone_source: "ubuntu-24.04-large-plus"
|
||||
vm_size: "large-plus"
|
||||
|
||||
# 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
|
||||
|
||||
@@ -3,8 +3,13 @@
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
|
||||
- name: Proxmox Clone VM Playbook
|
||||
ansible.builtin.import_playbook: proxmox_clone_vm.yml
|
||||
- name: Proxmox Clone Ubuntu VM Playbook
|
||||
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
|
||||
# ansible.builtin.import_playbook: add_dns_entry.yml
|
||||
|
||||
39
ansible/playbooks/proxmox_clone_ubuntu_vm.yml
Normal file
39
ansible/playbooks/proxmox_clone_ubuntu_vm.yml
Normal 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
|
||||
Reference in New Issue
Block a user