114 lines
3.9 KiB
YAML
114 lines
3.9 KiB
YAML
---
|
|
- name: Build vCenter disk list
|
|
ansible.builtin.set_fact:
|
|
virtualization_vmware_disks: "{{ virtualization_vmware_disks | default([]) + [virtualization_vmware_disk_cfg] }}"
|
|
vars:
|
|
virtualization_vmware_disk_cfg:
|
|
size_gb: "{{ item.size | int }}"
|
|
type: thin
|
|
datastore: "{{ hypervisor_cfg.storage }}"
|
|
loop: "{{ system_cfg.disks }}"
|
|
loop_control:
|
|
label: "{{ item | to_json }}"
|
|
changed_when: false
|
|
|
|
- name: Create VM in vCenter
|
|
delegate_to: localhost
|
|
vars:
|
|
virtualization_vmware_networks: >-
|
|
{%- set ns = namespace(out=[]) -%}
|
|
{%- for iface in system_cfg.network.interfaces -%}
|
|
{%- set entry = {'name': iface.bridge, 'type': 'dhcp'} -%}
|
|
{%- if (iface.vlan | default('') | string | length) > 0 -%}
|
|
{%- set entry = entry | combine({'vlan': iface.vlan | int}) -%}
|
|
{%- endif -%}
|
|
{%- set ns.out = ns.out + [entry] -%}
|
|
{%- endfor -%}
|
|
{{ ns.out }}
|
|
community.vmware.vmware_guest:
|
|
hostname: "{{ hypervisor_cfg.url }}"
|
|
username: "{{ hypervisor_cfg.username }}"
|
|
password: "{{ hypervisor_cfg.password }}"
|
|
validate_certs: "{{ hypervisor_cfg.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
|
|
annotation: |
|
|
{{ note if note is defined else '' }}
|
|
state: "{{ 'poweredoff' if virtualization_tpm2_enabled | bool else 'poweredon' }}"
|
|
disk: "{{ virtualization_vmware_disks }}"
|
|
hardware:
|
|
memory_mb: "{{ system_cfg.memory }}"
|
|
num_cpus: "{{ system_cfg.cpus }}"
|
|
boot_firmware: efi
|
|
secure_boot: false
|
|
cdrom: >-
|
|
{{
|
|
[ {
|
|
"controller_number": 0,
|
|
"unit_number": 0,
|
|
"controller_type": "sata",
|
|
"state": "present",
|
|
"type": "iso",
|
|
"iso_path": boot_iso
|
|
} ]
|
|
+
|
|
( [ {
|
|
"controller_number": 0,
|
|
"unit_number": 1,
|
|
"controller_type": "sata",
|
|
"state": "present",
|
|
"type": "iso",
|
|
"iso_path": rhel_iso
|
|
} ] if rhel_iso is defined and rhel_iso | length > 0 else [] )
|
|
}}
|
|
networks: "{{ virtualization_vmware_networks }}"
|
|
no_log: true
|
|
register: virtualization_vmware_create_result
|
|
|
|
- name: Set VM created fact when VM was powered on during creation
|
|
ansible.builtin.set_fact:
|
|
virtualization_vm_created_in_run: true
|
|
when:
|
|
- virtualization_vmware_create_result is defined
|
|
- not virtualization_tpm2_enabled | bool
|
|
- virtualization_vmware_create_result.changed | bool
|
|
|
|
- name: Ensure vTPM2 is enabled when required
|
|
when: virtualization_tpm2_enabled | bool
|
|
delegate_to: localhost
|
|
community.vmware.vmware_guest_tpm:
|
|
hostname: "{{ hypervisor_cfg.url }}"
|
|
username: "{{ hypervisor_cfg.username }}"
|
|
password: "{{ hypervisor_cfg.password }}"
|
|
validate_certs: "{{ hypervisor_cfg.certs | bool }}"
|
|
datacenter: "{{ hypervisor_cfg.datacenter }}"
|
|
folder: "{{ system_cfg.path if system_cfg.path | string | length > 0 else omit }}"
|
|
name: "{{ hostname }}"
|
|
state: present
|
|
no_log: true
|
|
|
|
- name: Start VM in vCenter
|
|
when: virtualization_tpm2_enabled | bool
|
|
delegate_to: localhost
|
|
vmware.vmware.vm_powerstate:
|
|
hostname: "{{ hypervisor_cfg.url }}"
|
|
username: "{{ hypervisor_cfg.username }}"
|
|
password: "{{ hypervisor_cfg.password }}"
|
|
validate_certs: "{{ hypervisor_cfg.certs | bool }}"
|
|
datacenter: "{{ hypervisor_cfg.datacenter }}"
|
|
name: "{{ hostname }}"
|
|
state: powered-on
|
|
no_log: true
|
|
register: virtualization_vmware_start_result
|
|
|
|
- name: Set VM created fact when VM was started separately (TPM2 case)
|
|
ansible.builtin.set_fact:
|
|
virtualization_vm_created_in_run: true
|
|
when:
|
|
- virtualization_tpm2_enabled | bool
|
|
- virtualization_vmware_start_result is defined
|
|
- virtualization_vmware_start_result.changed | bool
|