refactor(vars): remove legacy variable inputs
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user