43 lines
1.9 KiB
YAML
43 lines
1.9 KiB
YAML
---
|
|
- name: Validate hypervisor dict input
|
|
when: hypervisor is mapping
|
|
ansible.builtin.assert:
|
|
that:
|
|
- hypervisor.type is defined
|
|
- hypervisor.type | string | length > 0
|
|
fail_msg: "hypervisor.type is required when hypervisor is a dictionary"
|
|
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)
|
|
}}
|
|
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 }}"
|
|
changed_when: false
|