71 lines
2.8 KiB
YAML
71 lines
2.8 KiB
YAML
---
|
|
- 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: raw
|
|
|
|
- name: Retrieve information about specific VM by name and get current configuration
|
|
community.proxmox.proxmox_vm_info:
|
|
api_user: "{{ proxmox_user }}"
|
|
api_password: "{{ proxmox_password }}"
|
|
api_host: "{{ proxmox_host }}"
|
|
name: "{{ inventory_hostname }}"
|
|
config: current
|
|
register: proxmox_vm_info
|
|
|
|
- name: Extract net0 information
|
|
set_fact:
|
|
vm_net0: "{{ proxmox_vm_info.proxmox_vms[0].config.net0 }}"
|
|
|
|
- name: Extract MAC address using regex
|
|
set_fact:
|
|
vm_mac_address: "{{ vm_net0 | regex_search('([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}') }}"
|
|
|
|
# Create DNS Entry
|
|
# Create DHCP Reservation
|
|
#
|
|
# - name: Start VM
|
|
# community.proxmox.proxmox_kvm:
|
|
# api_user: "{{ proxmox_user }}"
|
|
# api_password: "{{ proxmox_password }}"
|
|
# api_host: "{{ proxmox_host }}"
|
|
# name: "{{ inventory_hostname }}"
|
|
# node: "{{ proxmox_target_node }}"
|
|
# state: started
|
|
|
|
# - 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
|
|
|
|
# - name: Set hostname of cloned VM
|
|
# delegate_to: "{{ inventory_hostname }}"
|
|
# ansible.builtin.hostname:
|
|
# name: "{{ hostname }}"
|