refactor(vars): remove legacy variable inputs

This commit is contained in:
2026-02-11 05:37:18 +01:00
parent fc05708466
commit 9101e12126
20 changed files with 159 additions and 199 deletions

View File

@@ -42,7 +42,7 @@
- role: environment
vars:
ansible_connection: "{{ 'vmware_tools' if hypervisor == 'vmware' else 'ssh' }}"
ansible_connection: "{{ 'vmware_tools' if hypervisor_type == 'vmware' else 'ssh' }}"
- role: partitioning
vars:

View File

@@ -1,6 +1,6 @@
---
- name: Remove Archiso and cloud-init disks
when: hypervisor == "libvirt"
when: hypervisor_type == "libvirt"
delegate_to: localhost
become: false
block:

View File

@@ -1,14 +1,14 @@
---
- name: Setup Cleanup
when: hypervisor == "proxmox"
when: hypervisor_type == "proxmox"
delegate_to: localhost
become: false
block:
- name: Cleanup Setup Disks
community.proxmox.proxmox_disk:
api_host: "{{ hypervisor_url }}"
api_user: "{{ hypervisor_username }}"
api_password: "{{ hypervisor_password }}"
api_host: "{{ hypervisor_cfg.url }}"
api_user: "{{ hypervisor_cfg.username }}"
api_password: "{{ hypervisor_cfg.password }}"
name: "{{ hostname }}"
vmid: "{{ system_cfg.id }}"
disk: "{{ item }}"
@@ -19,9 +19,9 @@
- name: Start the VM
community.proxmox.proxmox_kvm:
api_host: "{{ hypervisor_url }}"
api_user: "{{ hypervisor_username }}"
api_password: "{{ hypervisor_password }}"
node: "{{ hypervisor_node }}"
api_host: "{{ hypervisor_cfg.url }}"
api_user: "{{ hypervisor_cfg.username }}"
api_password: "{{ hypervisor_cfg.password }}"
node: "{{ hypervisor_cfg.node }}"
vmid: "{{ system_cfg.id }}"
state: restarted

View File

@@ -63,7 +63,7 @@
- name: Remove VM for libvirt
when:
- hypervisor == "libvirt"
- hypervisor_type == "libvirt"
- virtualization_vm_created_in_run | default(false) | bool
delegate_to: localhost
become: false
@@ -73,7 +73,7 @@
- name: Undefine VM for libvirt
when:
- hypervisor == "libvirt"
- hypervisor_type == "libvirt"
- virtualization_vm_created_in_run | default(false) | bool
delegate_to: localhost
become: false
@@ -83,7 +83,7 @@
- name: Remove VM disk for libvirt
when:
- hypervisor == "libvirt"
- hypervisor_type == "libvirt"
- virtualization_vm_created_in_run | default(false) | bool
delegate_to: localhost
become: false
@@ -96,7 +96,7 @@
- name: Remove cloud-init disk for libvirt
when:
- hypervisor == "libvirt"
- hypervisor_type == "libvirt"
- virtualization_vm_created_in_run | default(false) | bool
delegate_to: localhost
become: false
@@ -106,30 +106,30 @@
- name: Remove VM for proxmox
when:
- hypervisor == "proxmox"
- hypervisor_type == "proxmox"
- virtualization_vm_created_in_run | default(false) | bool
delegate_to: localhost
become: false
community.proxmox.proxmox_kvm:
api_host: "{{ hypervisor_url }}"
api_user: "{{ hypervisor_username }}"
api_password: "{{ hypervisor_password }}"
node: "{{ hypervisor_node }}"
api_host: "{{ hypervisor_cfg.url }}"
api_user: "{{ hypervisor_cfg.username }}"
api_password: "{{ hypervisor_cfg.password }}"
node: "{{ hypervisor_cfg.node }}"
name: "{{ hostname }}"
vmid: "{{ system_cfg.id }}"
state: stopped
- name: Delete VM for proxmox
when:
- hypervisor == "proxmox"
- hypervisor_type == "proxmox"
- virtualization_vm_created_in_run | default(false) | bool
delegate_to: localhost
become: false
community.proxmox.proxmox_kvm:
api_host: "{{ hypervisor_url }}"
api_user: "{{ hypervisor_username }}"
api_password: "{{ hypervisor_password }}"
node: "{{ hypervisor_node }}"
api_host: "{{ hypervisor_cfg.url }}"
api_user: "{{ hypervisor_cfg.username }}"
api_password: "{{ hypervisor_cfg.password }}"
node: "{{ hypervisor_cfg.node }}"
name: "{{ hostname }}"
vmid: "{{ system_cfg.id }}"
state: absent
@@ -137,37 +137,37 @@
- name: Remove VM for VMware
when:
- hypervisor == "vmware"
- hypervisor_type == "vmware"
- virtualization_vm_created_in_run | default(false) | bool
delegate_to: localhost
become: false
community.vmware.vmware_guest:
hostname: "{{ hypervisor_url }}"
username: "{{ hypervisor_username }}"
password: "{{ hypervisor_password }}"
validate_certs: "{{ hypervisor_validate_certs }}"
hostname: "{{ hypervisor_cfg.url }}"
username: "{{ hypervisor_cfg.username }}"
password: "{{ hypervisor_cfg.password }}"
validate_certs: "{{ hypervisor_cfg.validate_certs | bool }}"
name: "{{ hostname }}"
folder: "{{ system_cfg.path | default('/') }}"
state: poweredoff
- name: Delete VM for VMware
when:
- hypervisor == "vmware"
- hypervisor_type == "vmware"
- virtualization_vm_created_in_run | default(false) | bool
delegate_to: localhost
become: false
community.vmware.vmware_guest:
hostname: "{{ hypervisor_url }}"
username: "{{ hypervisor_username }}"
password: "{{ hypervisor_password }}"
validate_certs: "{{ hypervisor_validate_certs }}"
hostname: "{{ hypervisor_cfg.url }}"
username: "{{ hypervisor_cfg.username }}"
password: "{{ hypervisor_cfg.password }}"
validate_certs: "{{ hypervisor_cfg.validate_certs | bool }}"
name: "{{ hostname }}"
folder: "{{ system_cfg.path | default('/') }}"
state: absent
- name: Destroy Xen VM if running
when:
- hypervisor == "xen"
- hypervisor_type == "xen"
- virtualization_vm_created_in_run | default(false) | bool
delegate_to: localhost
become: false
@@ -182,7 +182,7 @@
- name: Remove Xen VM disk
when:
- hypervisor == "xen"
- hypervisor_type == "xen"
- virtualization_vm_created_in_run | default(false) | bool
delegate_to: localhost
become: false
@@ -195,7 +195,7 @@
- name: Remove Xen VM config file
when:
- hypervisor == "xen"
- hypervisor_type == "xen"
- virtualization_vm_created_in_run | default(false) | bool
delegate_to: localhost
become: false

View File

@@ -1,17 +1,17 @@
---
- name: Clean vCenter VM
when: hypervisor == "vmware"
when: hypervisor_type == "vmware"
delegate_to: localhost
become: false
block:
- name: Remove CD-ROM from VM in vCenter
when: hypervisor == "vmware"
when: hypervisor_type == "vmware"
community.vmware.vmware_guest:
hostname: "{{ hypervisor_url }}"
username: "{{ hypervisor_username }}"
password: "{{ hypervisor_password }}"
validate_certs: "{{ hypervisor_validate_certs }}"
datacenter: "{{ hypervisor_datacenter }}"
hostname: "{{ hypervisor_cfg.url }}"
username: "{{ hypervisor_cfg.username }}"
password: "{{ hypervisor_cfg.password }}"
validate_certs: "{{ hypervisor_cfg.validate_certs | bool }}"
datacenter: "{{ hypervisor_cfg.datacenter }}"
name: "{{ hostname }}"
cdrom:
- controller_number: 0
@@ -29,12 +29,12 @@
failed_when: false
- name: Start VM in vCenter
when: hypervisor == "vmware"
when: hypervisor_type == "vmware"
vmware.vmware.vm_powerstate:
hostname: "{{ hypervisor_url }}"
username: "{{ hypervisor_username }}"
password: "{{ hypervisor_password }}"
validate_certs: "{{ hypervisor_validate_certs }}"
datacenter: "{{ hypervisor_datacenter }}"
hostname: "{{ hypervisor_cfg.url }}"
username: "{{ hypervisor_cfg.username }}"
password: "{{ hypervisor_cfg.password }}"
validate_certs: "{{ hypervisor_cfg.validate_certs | bool }}"
datacenter: "{{ hypervisor_cfg.datacenter }}"
name: "{{ hostname }}"
state: powered-on

View File

@@ -1,6 +1,6 @@
---
- name: Cleanup Xen installer media
when: hypervisor == "xen"
when: hypervisor_type == "xen"
delegate_to: localhost
become: false
block:

View File

@@ -29,7 +29,7 @@
configuration_fstab_dvd_line: >-
{{
'/usr/local/install/redhat/rhel.iso /usr/local/install/redhat/dvd iso9660 loop,nofail 0 0'
if hypervisor == 'vmware'
if hypervisor_type == 'vmware'
else '/dev/sr0 /usr/local/install/redhat/dvd iso9660 ro,relatime,nojoliet,check=s,map=n,nofail 0 0'
}}
ansible.builtin.lineinfile:
@@ -39,7 +39,7 @@
state: present
- name: Write image from RHEL ISO to the target machine
when: os == "rhel" and hypervisor == 'vmware'
when: os == "rhel" and hypervisor_type == 'vmware'
ansible.builtin.command:
argv:
- dd

View File

@@ -1,6 +1,6 @@
---
- name: Configure work environment
become: "{{ hypervisor != 'vmware' }}"
become: "{{ hypervisor_type != 'vmware' }}"
block:
- name: Wait for connection
ansible.builtin.wait_for_connection:
@@ -81,7 +81,7 @@
msg: This host is not booted from the Arch install media!
- name: Select primary Network Interface
when: hypervisor == "vmware"
when: hypervisor_type == "vmware"
ansible.builtin.set_fact:
environment_interface_name: >-
{{
@@ -97,7 +97,7 @@
- name: Set IP-Address
when:
- hypervisor == "vmware"
- hypervisor_type == "vmware"
- system_cfg.ip is defined and system_cfg.ip | string | length > 0
ansible.builtin.command: >-
ip addr replace {{ system_cfg.ip }}/{{ system_cfg.prefix }}
@@ -107,7 +107,7 @@
- name: Set Default Gateway
when:
- hypervisor == "vmware"
- hypervisor_type == "vmware"
- system_cfg.gateway is defined and system_cfg.gateway | string | length > 0
- system_cfg.ip is defined and system_cfg.ip | string | length > 0
ansible.builtin.command: "ip route replace default via {{ system_cfg.gateway }}"
@@ -120,7 +120,7 @@
changed_when: false
- name: Configure SSH for root login
when: hypervisor == "vmware" and vmware_ssh | bool
when: hypervisor_type == "vmware" and vmware_ssh | bool
block:
- name: Allow login
ansible.builtin.replace:
@@ -192,7 +192,7 @@
environment_rhel_iso_device: >-
{{
'/dev/sr2'
if hypervisor == 'libvirt'
if hypervisor_type == 'libvirt'
else '/dev/sr1'
}}
changed_when: false

View File

@@ -1,5 +1,7 @@
---
hypervisor: "none"
# User input. Normalized into hypervisor_cfg + hypervisor_type.
hypervisor:
type: "none"
hypervisor_defaults:
type: "none"
url: ""

View File

@@ -1,42 +1,26 @@
---
- name: Validate hypervisor dict input
when: hypervisor is mapping
- name: Ensure hypervisor input is a dictionary
ansible.builtin.set_fact:
hypervisor: "{{ hypervisor | default({}) }}"
changed_when: false
- name: Validate hypervisor input
ansible.builtin.assert:
that:
- hypervisor is mapping
- hypervisor.type is defined
- hypervisor.type | string | length > 0
fail_msg: "hypervisor.type is required when hypervisor is a dictionary"
fail_msg: "hypervisor must be a dictionary and hypervisor.type must be set (e.g. libvirt|proxmox|vmware|xen|none)."
quiet: true
- name: Normalize hypervisor configuration
vars:
hypervisor_input: "{{ hypervisor if hypervisor is mapping else {} }}"
hypervisor_type_legacy: "{{ (hypervisor | default('none')) if hypervisor is string else '' }}"
hypervisor_legacy_cfg:
type: "{{ hypervisor_type_legacy }}"
url: "{{ hypervisor_url | default('') }}"
username: "{{ hypervisor_username | default('') }}"
password: "{{ hypervisor_password | default('') }}"
node: "{{ hypervisor_node | default('') }}"
storage: "{{ hypervisor_storage | default('') }}"
datacenter: "{{ hypervisor_datacenter | default('') }}"
cluster: "{{ hypervisor_cluster | default('') }}"
validate_certs: "{{ hypervisor_validate_certs | default(false) | bool }}"
hypervisor_cfg_effective: >-
{{
hypervisor_defaults
| combine(hypervisor_legacy_cfg, recursive=True)
| combine(hypervisor_input, recursive=True)
| combine(hypervisor, recursive=True)
}}
ansible.builtin.set_fact:
hypervisor_cfg: "{{ hypervisor_cfg_effective }}"
hypervisor: "{{ hypervisor_cfg_effective.type | string | lower }}"
hypervisor_url: "{{ hypervisor_cfg_effective.url }}"
hypervisor_username: "{{ hypervisor_cfg_effective.username }}"
hypervisor_password: "{{ hypervisor_cfg_effective.password }}"
hypervisor_node: "{{ hypervisor_cfg_effective.node }}"
hypervisor_storage: "{{ hypervisor_cfg_effective.storage }}"
hypervisor_datacenter: "{{ hypervisor_cfg_effective.datacenter }}"
hypervisor_cluster: "{{ hypervisor_cfg_effective.cluster }}"
hypervisor_validate_certs: "{{ hypervisor_cfg_effective.validate_certs | bool }}"
hypervisor_type: "{{ hypervisor_cfg_effective.type | string | lower }}"
changed_when: false

View File

@@ -64,7 +64,7 @@
- name: Set SSH access
when:
- install_type == "virtual"
- hypervisor != "vmware"
- hypervisor_type != "vmware"
ansible.builtin.set_fact:
ansible_user: "{{ user_name }}"
ansible_password: "{{ user_password }}"
@@ -73,7 +73,7 @@
changed_when: false
- name: Set connection for VMware
when: hypervisor == "vmware"
when: hypervisor_type == "vmware"
ansible.builtin.set_fact:
ansible_connection: vmware_tools
changed_when: false

View File

@@ -17,87 +17,79 @@
{{
system.name
if system.name is defined and (system.name | string | length) > 0
else (
hostname
if hostname is defined and (hostname | string | length) > 0
else inventory_hostname
)
else inventory_hostname
}}
system_id_effective: >-
{{
system.id
if system.id is defined and (system.id | string | length) > 0
else (vm_id | default(''))
else ''
}}
system_cpus_effective: >-
{{
system.cpus
if system.cpus is defined and (system.cpus | int) > 0
else (vm_cpus | default(0))
else 0
}}
system_memory_mb_effective: >-
{{
system.memory_mb
if system.memory_mb is defined and (system.memory_mb | int) > 0
else (vm_memory | default(0))
else 0
}}
system_balloon_mb_effective: >-
{{
system.balloon_mb
if system.balloon_mb is defined and (system.balloon_mb | int) > 0
else (vm_ballo | default(''))
else 0
}}
system_network_effective: >-
{{
system.network
if system.network is defined and (system.network | string | length) > 0
else (vm_nif | default(''))
else ''
}}
system_vlan_effective: >-
{{
system.vlan
if system.vlan is defined and (system.vlan | string | length) > 0
else (vlan_name | default(''))
else ''
}}
system_ip_effective: >-
{{
system.ip
if system.ip is defined and (system.ip | string | length) > 0
else (vm_ip | default(''))
else ''
}}
system_prefix_effective: >-
{{
system.prefix
if system.prefix is defined and (system.prefix | int) > 0
else (vm_nms | default(''))
else ''
}}
system_gateway_effective: >-
{{
system.gateway
if system.gateway is defined and (system.gateway | string | length) > 0
else (vm_gw | default(''))
else ''
}}
system_dns_servers_effective: >-
{{
system.dns_servers
if system.dns_servers is defined
else (vm_dns | default([]))
else []
}}
system_dns_search_effective: >-
{{
system.dns_search
if system.dns_search is defined
else (vm_dns_search | default([]))
else []
}}
system_path_effective: >-
{{
system.path
if system.path is defined and (system.path | string | length) > 0
else (
system.hypervisor_path
if system.hypervisor_path is defined and (system.hypervisor_path | string | length) > 0
else (vm_path | default(''))
)
else ''
}}
ansible.builtin.set_fact:
hostname: "{{ system_name_effective }}"
@@ -141,29 +133,21 @@
if system_cfg.disks is defined
else []
}}
system_disks_legacy: >-
{{
[ {'size': vm_size} ]
if (system_disks_raw | length) == 0 and (vm_size is defined and (vm_size | float) > 0)
else []
}}
system_disks_effective: >-
{{
system_disks_raw
if (system_disks_raw | length) > 0
else system_disks_legacy
}}
system_disk_device_prefix: >-
{{
'/dev/vd'
if (install_type | default('')) == 'virtual' and (hypervisor | default('')) == 'libvirt'
if (install_type | default('')) == 'virtual' and (hypervisor_type | default('')) == 'libvirt'
else (
'/dev/xvd'
if (install_type | default('')) == 'virtual' and (hypervisor | default('')) == 'xen'
if (install_type | default('')) == 'virtual' and (hypervisor_type | default('')) == 'xen'
else (
'/dev/sd'
if (install_type | default('')) == 'virtual'
and (hypervisor | default('')) in ['proxmox', 'vmware']
and (hypervisor_type | default('')) in ['proxmox', 'vmware']
else ''
)
)
@@ -272,20 +256,3 @@
ansible.builtin.set_fact:
install_drive: "{{ system_disks_cfg[0].device }}"
changed_when: false
- name: Set legacy vm_* aliases (compat)
ansible.builtin.set_fact:
vm_id: "{{ system_cfg.id }}"
vm_cpus: "{{ system_cfg.cpus }}"
vm_memory: "{{ system_cfg.memory_mb }}"
vm_ballo: "{{ system_cfg.balloon_mb }}"
vm_nif: "{{ system_cfg.network }}"
vlan_name: "{{ system_cfg.vlan }}"
vm_ip: "{{ system_cfg.ip }}"
vm_nms: "{{ system_cfg.prefix }}"
vm_gw: "{{ system_cfg.gateway }}"
vm_dns: "{{ system_cfg.dns_servers }}"
vm_dns_search: "{{ system_cfg.dns_search }}"
vm_path: "{{ system_cfg.path }}"
vm_size: "{{ (system_cfg.disks | default([]) | first | default({})).size | default(0) }}"
changed_when: false

View File

@@ -4,8 +4,10 @@
that:
- install_type is defined
- install_type in ["virtual", "physical"]
- hypervisor is defined
- hypervisor in ["libvirt", "proxmox", "vmware", "xen", "none"]
- hypervisor_cfg is defined
- hypervisor_cfg is mapping
- hypervisor_type is defined
- hypervisor_type in ["libvirt", "proxmox", "vmware", "xen", "none"]
- filesystem is defined
- filesystem in ["btrfs", "ext4", "xfs"]
- install_drive is defined
@@ -18,7 +20,7 @@
- name: Validate install_type/hypervisor relationship
ansible.builtin.assert:
that:
- install_type == "physical" or hypervisor in ["libvirt", "proxmox", "vmware", "xen"]
- install_type == "physical" or hypervisor_type in ["libvirt", "proxmox", "vmware", "xen"]
fail_msg: "hypervisor must be one of: libvirt, proxmox, vmware, xen when install_type=virtual."
quiet: true
@@ -58,7 +60,7 @@
- name: Validate Proxmox hypervisor inputs
when:
- install_type == "virtual"
- hypervisor == "proxmox"
- hypervisor_type == "proxmox"
ansible.builtin.assert:
that:
- hypervisor_cfg.url | string | length > 0
@@ -74,7 +76,7 @@
- name: Validate VMware hypervisor inputs
when:
- install_type == "virtual"
- hypervisor == "vmware"
- hypervisor_type == "vmware"
ansible.builtin.assert:
that:
- hypervisor_cfg.url | string | length > 0
@@ -90,7 +92,7 @@
- name: Validate Xen hypervisor inputs
when:
- install_type == "virtual"
- hypervisor == "xen"
- hypervisor_type == "xen"
ansible.builtin.assert:
that:
- system_cfg.network | string | length > 0
@@ -125,7 +127,7 @@
that:
- system_cfg is defined
- system_cfg is mapping
fail_msg: "system configuration is missing. Define system: {...} or legacy vm_* variables."
fail_msg: "system configuration is missing. Define system: {...}."
quiet: true
- name: Validate virtual system sizing

View File

@@ -119,7 +119,13 @@ partitioning_vm_size_effective: >-
(
partitioning_vm_size
if (partitioning_vm_size is defined and (partitioning_vm_size | float) > 0)
else (vm_size if vm_size is defined else 0)
else (
(
(system_cfg.disks | default([]) | first | default({})).size
if system_cfg is defined
else 0
) | default(0)
)
)
| float
}}
@@ -128,7 +134,10 @@ partitioning_vm_memory_effective: >-
(
partitioning_vm_memory
if (partitioning_vm_memory is defined and (partitioning_vm_memory | float) > 0)
else (vm_memory if vm_memory is defined else 0)
else (
(system_cfg.memory_mb if system_cfg is defined else 0)
| default(0)
)
)
| float
}}

View File

@@ -3,7 +3,7 @@
when:
- swap_enabled | bool
- partitioning_vm_memory is not defined or (partitioning_vm_memory | float) <= 0
- vm_memory is not defined or (vm_memory | float) <= 0
- system_cfg is not defined or (system_cfg.memory_mb | default(0) | float) <= 0
block:
- name: Read system memory
ansible.builtin.command: awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo
@@ -19,7 +19,6 @@
when:
- install_type == "physical"
- partitioning_vm_size is not defined or (partitioning_vm_size | float) <= 0
- vm_size is not defined or (vm_size | float) <= 0
- install_drive | length > 0
block:
- name: Detect install drive size

View File

@@ -82,7 +82,7 @@
when: install_type == "virtual"
block:
- name: Check if VM already exists on libvirt
when: hypervisor == "libvirt"
when: hypervisor_type == "libvirt"
delegate_to: localhost
become: false
community.libvirt.virt:
@@ -92,7 +92,7 @@
failed_when: false
- name: Abort if VM already exists on libvirt
when: hypervisor == "libvirt"
when: hypervisor_type == "libvirt"
ansible.builtin.assert:
that:
- hostname not in system_check_libvirt_existing_vms.domains | default([])
@@ -103,14 +103,14 @@
quiet: true
- name: Check if VM already exists on Proxmox
when: hypervisor == "proxmox"
when: hypervisor_type == "proxmox"
delegate_to: localhost
become: false
community.proxmox.proxmox_vm_info:
api_host: "{{ hypervisor_url }}"
api_user: "{{ hypervisor_username }}"
api_password: "{{ hypervisor_password }}"
node: "{{ hypervisor_node }}"
api_host: "{{ hypervisor_cfg.url }}"
api_user: "{{ hypervisor_cfg.username }}"
api_password: "{{ hypervisor_cfg.password }}"
node: "{{ hypervisor_cfg.node }}"
vmid: "{{ system_cfg.id }}"
name: "{{ hostname }}"
type: qemu
@@ -118,7 +118,7 @@
changed_when: false
- name: Abort if VM already exists on Proxmox
when: hypervisor == "proxmox"
when: hypervisor_type == "proxmox"
ansible.builtin.assert:
that:
- system_check_proxmox_check_result.proxmox_vms | default([]) | length == 0
@@ -129,14 +129,14 @@
quiet: true
- name: Check if VM already exists in vCenter
when: hypervisor == "vmware"
when: hypervisor_type == "vmware"
delegate_to: localhost
community.vmware.vmware_guest_info:
hostname: "{{ hypervisor_url }}"
username: "{{ hypervisor_username }}"
password: "{{ hypervisor_password }}"
validate_certs: "{{ hypervisor_validate_certs }}"
datacenter: "{{ hypervisor_datacenter }}"
hostname: "{{ hypervisor_cfg.url }}"
username: "{{ hypervisor_cfg.username }}"
password: "{{ hypervisor_cfg.password }}"
validate_certs: "{{ hypervisor_cfg.validate_certs | bool }}"
datacenter: "{{ hypervisor_cfg.datacenter }}"
name: "{{ hostname }}"
folder: "{{ system_cfg.path if system_cfg.path | length > 0 else omit }}"
register: system_check_vmware_check_result
@@ -144,7 +144,7 @@
changed_when: false
- name: Fail if vCenter lookup failed unexpectedly
when: hypervisor == "vmware"
when: hypervisor_type == "vmware"
ansible.builtin.assert:
that:
- not system_check_vmware_check_result.failed
@@ -155,7 +155,7 @@
quiet: true
- name: Abort if VM already exists in vCenter
when: hypervisor == "vmware"
when: hypervisor_type == "vmware"
ansible.builtin.assert:
that:
- system_check_vmware_check_result.instance is not defined
@@ -166,7 +166,7 @@
quiet: true
- name: Check if VM already exists on Xen
when: hypervisor == "xen"
when: hypervisor_type == "xen"
delegate_to: localhost
ansible.builtin.command:
argv:
@@ -177,7 +177,7 @@
failed_when: false
- name: Abort if VM already exists on Xen
when: hypervisor == "xen"
when: hypervisor_type == "xen"
ansible.builtin.assert:
that:
- hostname not in system_check_xen_existing_vms.stdout | default('')

View File

@@ -1,3 +1,3 @@
---
- name: Create Virtual Machine
ansible.builtin.include_tasks: "{{ hypervisor }}.yml"
ansible.builtin.include_tasks: "{{ hypervisor_type }}.yml"

View File

@@ -23,17 +23,17 @@
virtualization_proxmox_scsi: >-
{%- set out = {} -%}
{%- for disk in system_cfg.disks -%}
{%- set _ = out.update({ 'scsi' ~ loop.index0: hypervisor_storage ~ ':' ~ (disk.size | int) }) -%}
{%- set _ = out.update({ 'scsi' ~ loop.index0: hypervisor_cfg.storage ~ ':' ~ (disk.size | int) }) -%}
{%- endfor -%}
{{ out }}
community.proxmox.proxmox_kvm:
api_host: "{{ hypervisor_url }}"
api_user: "{{ hypervisor_username }}"
api_password: "{{ hypervisor_password }}"
api_host: "{{ hypervisor_cfg.url }}"
api_user: "{{ hypervisor_cfg.username }}"
api_password: "{{ hypervisor_cfg.password }}"
ciuser: "{{ user_name }}"
cipassword: "{{ user_password }}"
ciupgrade: false
node: "{{ hypervisor_node }}"
node: "{{ hypervisor_cfg.node }}"
vmid: "{{ system_cfg.id }}"
name: "{{ hostname }}"
cpu: host
@@ -53,17 +53,17 @@
efitype: 4m
format: raw
pre_enrolled_keys: false
storage: "{{ hypervisor_storage }}"
storage: "{{ hypervisor_cfg.storage }}"
tpmstate0: >-
{{
{'storage': hypervisor_storage, 'version': '2.0'}
{'storage': hypervisor_cfg.storage, 'version': '2.0'}
if virtualization_tpm2_enabled | bool
else omit
}}
ide:
ide0: "{{ boot_iso }},media=cdrom"
ide1: "{{ rhel_iso + ',media=cdrom' if rhel_iso is defined and rhel_iso | length > 0 else omit }}"
ide2: "{{ hypervisor_storage }}:cloudinit"
ide2: "{{ hypervisor_cfg.storage }}:cloudinit"
net:
net0: >-
virtio,bridge={{ system_cfg.network }}{% if system_cfg.vlan is defined and system_cfg.vlan | string | length > 0 %},tag={{ system_cfg.vlan }}{% endif %}
@@ -83,10 +83,10 @@
- name: Start VM on Proxmox
delegate_to: localhost
community.proxmox.proxmox_kvm:
api_host: "{{ hypervisor_url }}"
api_user: "{{ hypervisor_username }}"
api_password: "{{ hypervisor_password }}"
node: "{{ hypervisor_node }}"
api_host: "{{ hypervisor_cfg.url }}"
api_user: "{{ hypervisor_cfg.username }}"
api_password: "{{ hypervisor_cfg.password }}"
node: "{{ hypervisor_cfg.node }}"
name: "{{ hostname }}"
vmid: "{{ system_cfg.id }}"
state: started

View File

@@ -6,7 +6,7 @@
virtualization_vmware_disk_cfg:
size_gb: "{{ item.size | int }}"
type: thin
datastore: "{{ hypervisor_storage }}"
datastore: "{{ hypervisor_cfg.storage }}"
loop: "{{ system_cfg.disks }}"
loop_control:
label: "{{ item | to_json }}"
@@ -15,12 +15,12 @@
- name: Create VM in vCenter
delegate_to: localhost
community.vmware.vmware_guest:
hostname: "{{ hypervisor_url }}"
username: "{{ hypervisor_username }}"
password: "{{ hypervisor_password }}"
validate_certs: "{{ hypervisor_validate_certs }}"
datacenter: "{{ hypervisor_datacenter }}"
cluster: "{{ hypervisor_cluster }}"
hostname: "{{ hypervisor_cfg.url }}"
username: "{{ hypervisor_cfg.username }}"
password: "{{ hypervisor_cfg.password }}"
validate_certs: "{{ hypervisor_cfg.validate_certs | bool }}"
datacenter: "{{ hypervisor_cfg.datacenter }}"
cluster: "{{ hypervisor_cfg.cluster }}"
folder: "{{ system_cfg.path if system_cfg.path | string | length > 0 else omit }}"
name: "{{ hostname }}"
guest_id: otherLinux64Guest
@@ -71,11 +71,11 @@
when: virtualization_tpm2_enabled | bool
delegate_to: localhost
community.vmware.vmware_guest_tpm:
hostname: "{{ hypervisor_url }}"
username: "{{ hypervisor_username }}"
password: "{{ hypervisor_password }}"
validate_certs: "{{ hypervisor_validate_certs }}"
datacenter: "{{ hypervisor_datacenter }}"
hostname: "{{ hypervisor_cfg.url }}"
username: "{{ hypervisor_cfg.username }}"
password: "{{ hypervisor_cfg.password }}"
validate_certs: "{{ hypervisor_cfg.validate_certs | bool }}"
datacenter: "{{ hypervisor_cfg.datacenter }}"
folder: "{{ system_cfg.path if system_cfg.path | string | length > 0 else omit }}"
name: "{{ hostname }}"
state: present
@@ -84,11 +84,11 @@
when: virtualization_tpm2_enabled | bool
delegate_to: localhost
vmware.vmware.vm_powerstate:
hostname: "{{ hypervisor_url }}"
username: "{{ hypervisor_username }}"
password: "{{ hypervisor_password }}"
validate_certs: "{{ hypervisor_validate_certs }}"
datacenter: "{{ hypervisor_datacenter }}"
hostname: "{{ hypervisor_cfg.url }}"
username: "{{ hypervisor_cfg.username }}"
password: "{{ hypervisor_cfg.password }}"
validate_certs: "{{ hypervisor_cfg.validate_certs | bool }}"
datacenter: "{{ hypervisor_cfg.datacenter }}"
name: "{{ hostname }}"
state: powered-on
register: virtualization_vmware_start_result

View File

@@ -21,9 +21,6 @@ hypervisor:
cluster: "cluster01"
validate_certs: false
# Legacy (still supported): hypervisor_url, hypervisor_username, hypervisor_password, hypervisor_node, hypervisor_storage,
# hypervisor_datacenter, hypervisor_cluster, hypervisor_validate_certs.
# VMware (only needed when hypervisor: vmware)
# system:
# path: "/Folder" # Optional folder path segment in vCenter.