refactor(virt): adopt module_defaults for hypervisor credentials
This commit is contained in:
@@ -3,12 +3,20 @@
|
|||||||
when: hypervisor_type == "proxmox"
|
when: hypervisor_type == "proxmox"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
become: false
|
become: false
|
||||||
|
module_defaults:
|
||||||
|
community.proxmox.proxmox_disk:
|
||||||
|
api_host: "{{ hypervisor_cfg.url }}"
|
||||||
|
api_user: "{{ hypervisor_cfg.username }}"
|
||||||
|
api_password: "{{ hypervisor_cfg.password }}"
|
||||||
|
community.proxmox.proxmox_kvm:
|
||||||
|
api_host: "{{ hypervisor_cfg.url }}"
|
||||||
|
api_user: "{{ hypervisor_cfg.username }}"
|
||||||
|
api_password: "{{ hypervisor_cfg.password }}"
|
||||||
|
node: "{{ hypervisor_cfg.host }}"
|
||||||
|
no_log: true
|
||||||
block:
|
block:
|
||||||
- name: Cleanup Setup Disks
|
- name: Cleanup Setup Disks
|
||||||
community.proxmox.proxmox_disk:
|
community.proxmox.proxmox_disk:
|
||||||
api_host: "{{ hypervisor_cfg.url }}"
|
|
||||||
api_user: "{{ hypervisor_cfg.username }}"
|
|
||||||
api_password: "{{ hypervisor_cfg.password }}"
|
|
||||||
name: "{{ hostname }}"
|
name: "{{ hostname }}"
|
||||||
vmid: "{{ system_cfg.id }}"
|
vmid: "{{ system_cfg.id }}"
|
||||||
disk: "{{ item }}"
|
disk: "{{ item }}"
|
||||||
@@ -17,14 +25,8 @@
|
|||||||
- ide0
|
- ide0
|
||||||
- ide2
|
- ide2
|
||||||
failed_when: false
|
failed_when: false
|
||||||
no_log: true
|
|
||||||
|
|
||||||
- name: Start the VM
|
- name: Start the VM
|
||||||
community.proxmox.proxmox_kvm:
|
community.proxmox.proxmox_kvm:
|
||||||
api_host: "{{ hypervisor_cfg.url }}"
|
|
||||||
api_user: "{{ hypervisor_cfg.username }}"
|
|
||||||
api_password: "{{ hypervisor_cfg.password }}"
|
|
||||||
node: "{{ hypervisor_cfg.host }}"
|
|
||||||
vmid: "{{ system_cfg.id }}"
|
vmid: "{{ system_cfg.id }}"
|
||||||
state: restarted
|
state: restarted
|
||||||
no_log: true
|
|
||||||
|
|||||||
@@ -3,14 +3,23 @@
|
|||||||
when: hypervisor_type == "vmware"
|
when: hypervisor_type == "vmware"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
become: false
|
become: false
|
||||||
|
module_defaults:
|
||||||
|
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 }}"
|
||||||
|
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 }}"
|
||||||
|
no_log: true
|
||||||
block:
|
block:
|
||||||
- name: Remove CD-ROM from VM in vCenter
|
- name: Remove CD-ROM from VM in vCenter
|
||||||
community.vmware.vmware_guest:
|
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 }}"
|
|
||||||
name: "{{ hostname }}"
|
name: "{{ hostname }}"
|
||||||
cdrom: >-
|
cdrom: >-
|
||||||
{{
|
{{
|
||||||
@@ -40,15 +49,8 @@
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
failed_when: false
|
failed_when: false
|
||||||
no_log: true
|
|
||||||
|
|
||||||
- name: Start VM in vCenter
|
- name: Start VM in vCenter
|
||||||
vmware.vmware.vm_powerstate:
|
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 }}"
|
name: "{{ hostname }}"
|
||||||
state: powered-on
|
state: powered-on
|
||||||
no_log: true
|
|
||||||
|
|||||||
@@ -33,70 +33,75 @@
|
|||||||
Please choose a different hostname or remove the existing VM manually before proceeding.
|
Please choose a different hostname or remove the existing VM manually before proceeding.
|
||||||
quiet: true
|
quiet: true
|
||||||
|
|
||||||
- name: Check if VM already exists on Proxmox
|
- name: Check VM existence on Proxmox
|
||||||
when: hypervisor_type == "proxmox"
|
when: hypervisor_type == "proxmox"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
become: false
|
become: false
|
||||||
community.proxmox.proxmox_vm_info:
|
module_defaults:
|
||||||
api_host: "{{ hypervisor_cfg.url }}"
|
community.proxmox.proxmox_vm_info:
|
||||||
api_user: "{{ hypervisor_cfg.username }}"
|
api_host: "{{ hypervisor_cfg.url }}"
|
||||||
api_password: "{{ hypervisor_cfg.password }}"
|
api_user: "{{ hypervisor_cfg.username }}"
|
||||||
node: "{{ hypervisor_cfg.host }}"
|
api_password: "{{ hypervisor_cfg.password }}"
|
||||||
vmid: "{{ system_cfg.id }}"
|
|
||||||
name: "{{ hostname }}"
|
|
||||||
type: qemu
|
|
||||||
register: system_check_proxmox_check_result
|
|
||||||
changed_when: false
|
|
||||||
no_log: true
|
no_log: true
|
||||||
|
block:
|
||||||
|
- name: Query Proxmox for existing VM
|
||||||
|
community.proxmox.proxmox_vm_info:
|
||||||
|
node: "{{ hypervisor_cfg.host }}"
|
||||||
|
vmid: "{{ system_cfg.id }}"
|
||||||
|
name: "{{ hostname }}"
|
||||||
|
type: qemu
|
||||||
|
register: system_check_proxmox_check_result
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Abort if VM already exists on Proxmox
|
- name: Abort if VM already exists on Proxmox
|
||||||
when: hypervisor_type == "proxmox"
|
ansible.builtin.assert:
|
||||||
ansible.builtin.assert:
|
that:
|
||||||
that:
|
- system_check_proxmox_check_result.proxmox_vms | default([]) | length == 0
|
||||||
- system_check_proxmox_check_result.proxmox_vms | default([]) | length == 0
|
fail_msg: |
|
||||||
fail_msg: |
|
VM {{ hostname }} (ID: {{ system_cfg.id }}) already exists on Proxmox hypervisor.
|
||||||
VM {{ hostname }} (ID: {{ system_cfg.id }}) already exists on Proxmox hypervisor.
|
To avoid data loss, the playbook will not overwrite or delete existing VMs.
|
||||||
To avoid data loss, the playbook will not overwrite or delete existing VMs.
|
Please choose a different hostname or VM ID, or remove the existing VM manually before proceeding.
|
||||||
Please choose a different hostname or VM ID, or remove the existing VM manually before proceeding.
|
quiet: true
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: Check if VM already exists in vCenter
|
- name: Check VM existence in vCenter
|
||||||
when: hypervisor_type == "vmware"
|
when: hypervisor_type == "vmware"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
community.vmware.vmware_guest_info:
|
module_defaults:
|
||||||
hostname: "{{ hypervisor_cfg.url }}"
|
community.vmware.vmware_guest_info:
|
||||||
username: "{{ hypervisor_cfg.username }}"
|
hostname: "{{ hypervisor_cfg.url }}"
|
||||||
password: "{{ hypervisor_cfg.password }}"
|
username: "{{ hypervisor_cfg.username }}"
|
||||||
validate_certs: "{{ hypervisor_cfg.certs | bool }}"
|
password: "{{ hypervisor_cfg.password }}"
|
||||||
datacenter: "{{ hypervisor_cfg.datacenter }}"
|
validate_certs: "{{ hypervisor_cfg.certs | bool }}"
|
||||||
name: "{{ hostname }}"
|
|
||||||
folder: "{{ system_cfg.path if system_cfg.path | length > 0 else omit }}"
|
|
||||||
register: system_check_vmware_check_result
|
|
||||||
failed_when: false
|
|
||||||
changed_when: false
|
|
||||||
no_log: true
|
no_log: true
|
||||||
|
block:
|
||||||
|
- name: Query vCenter for existing VM
|
||||||
|
community.vmware.vmware_guest_info:
|
||||||
|
datacenter: "{{ hypervisor_cfg.datacenter }}"
|
||||||
|
name: "{{ hostname }}"
|
||||||
|
folder: "{{ system_cfg.path if system_cfg.path | length > 0 else omit }}"
|
||||||
|
register: system_check_vmware_check_result
|
||||||
|
failed_when: false
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Fail if vCenter lookup failed unexpectedly
|
- name: Fail if vCenter lookup failed unexpectedly
|
||||||
when: hypervisor_type == "vmware"
|
ansible.builtin.assert:
|
||||||
ansible.builtin.assert:
|
that:
|
||||||
that:
|
- not system_check_vmware_check_result.failed
|
||||||
- not system_check_vmware_check_result.failed
|
or (system_check_vmware_check_result.msg is search('non-existing VM'))
|
||||||
or (system_check_vmware_check_result.msg is search('non-existing VM'))
|
fail_msg: |
|
||||||
fail_msg: |
|
Unable to verify VM existence in vCenter.
|
||||||
Unable to verify VM existence in vCenter.
|
{{ system_check_vmware_check_result.msg | default('Unknown error') }}
|
||||||
{{ system_check_vmware_check_result.msg | default('Unknown error') }}
|
quiet: true
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: Abort if VM already exists in vCenter
|
- name: Abort if VM already exists in vCenter
|
||||||
when: hypervisor_type == "vmware"
|
ansible.builtin.assert:
|
||||||
ansible.builtin.assert:
|
that:
|
||||||
that:
|
- system_check_vmware_check_result.instance is not defined
|
||||||
- system_check_vmware_check_result.instance is not defined
|
fail_msg: |
|
||||||
fail_msg: |
|
VM {{ hostname }} already exists in vCenter.
|
||||||
VM {{ hostname }} already exists in vCenter.
|
To avoid data loss, the playbook will not overwrite or delete existing VMs.
|
||||||
To avoid data loss, the playbook will not overwrite or delete existing VMs.
|
Please choose a different hostname or remove the existing VM manually before proceeding.
|
||||||
Please choose a different hostname or remove the existing VM manually before proceeding.
|
quiet: true
|
||||||
quiet: true
|
|
||||||
|
|
||||||
- name: Check if VM already exists on Xen
|
- name: Check if VM already exists on Xen
|
||||||
when: hypervisor_type == "xen"
|
when: hypervisor_type == "xen"
|
||||||
|
|||||||
@@ -1,95 +1,94 @@
|
|||||||
---
|
---
|
||||||
- name: Deploy VM on Proxmox
|
- name: Deploy VM on Proxmox
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
vars:
|
module_defaults:
|
||||||
virtualization_proxmox_scsi: >-
|
community.proxmox.proxmox_kvm:
|
||||||
{%- set out = {} -%}
|
api_host: "{{ hypervisor_cfg.url }}"
|
||||||
{%- for disk in system_cfg.disks -%}
|
api_user: "{{ hypervisor_cfg.username }}"
|
||||||
{%- set _ = out.update({ 'scsi' ~ loop.index0: hypervisor_cfg.storage ~ ':' ~ (disk.size | int) }) -%}
|
api_password: "{{ hypervisor_cfg.password }}"
|
||||||
{%- endfor -%}
|
node: "{{ hypervisor_cfg.host }}"
|
||||||
{{ out }}
|
block:
|
||||||
virtualization_proxmox_net: >-
|
- name: Create VM on Proxmox
|
||||||
{%- set out = {} -%}
|
vars:
|
||||||
{%- for iface in system_cfg.network.interfaces -%}
|
virtualization_proxmox_scsi: >-
|
||||||
{%- set val = 'virtio,bridge=' ~ iface.bridge -%}
|
{%- set out = {} -%}
|
||||||
{%- if iface.vlan | default('') | string | length > 0 -%}
|
{%- for disk in system_cfg.disks -%}
|
||||||
{%- set val = val ~ ',tag=' ~ iface.vlan -%}
|
{%- set _ = out.update({ 'scsi' ~ loop.index0: hypervisor_cfg.storage ~ ':' ~ (disk.size | int) }) -%}
|
||||||
{%- endif -%}
|
{%- endfor -%}
|
||||||
{%- set _ = out.update({ 'net' ~ loop.index0: val }) -%}
|
{{ out }}
|
||||||
{%- endfor -%}
|
virtualization_proxmox_net: >-
|
||||||
{{ out }}
|
{%- set out = {} -%}
|
||||||
virtualization_proxmox_ipconfig: >-
|
{%- for iface in system_cfg.network.interfaces -%}
|
||||||
{%- set out = {} -%}
|
{%- set val = 'virtio,bridge=' ~ iface.bridge -%}
|
||||||
{%- for iface in system_cfg.network.interfaces -%}
|
{%- if iface.vlan | default('') | string | length > 0 -%}
|
||||||
{%- if iface.ip | default('') | string | length > 0 -%}
|
{%- set val = val ~ ',tag=' ~ iface.vlan -%}
|
||||||
{%- set val = 'ip=' ~ iface.ip ~ '/' ~ iface.prefix
|
{%- endif -%}
|
||||||
~ ((',gw=' ~ iface.gateway) if (iface.gateway | default('') | length > 0) else '') -%}
|
{%- set _ = out.update({ 'net' ~ loop.index0: val }) -%}
|
||||||
{%- else -%}
|
{%- endfor -%}
|
||||||
{%- set val = 'ip=dhcp' -%}
|
{{ out }}
|
||||||
{%- endif -%}
|
virtualization_proxmox_ipconfig: >-
|
||||||
{%- set _ = out.update({ 'ipconfig' ~ loop.index0: val }) -%}
|
{%- set out = {} -%}
|
||||||
{%- endfor -%}
|
{%- for iface in system_cfg.network.interfaces -%}
|
||||||
{{ out }}
|
{%- if iface.ip | default('') | string | length > 0 -%}
|
||||||
community.proxmox.proxmox_kvm:
|
{%- set val = 'ip=' ~ iface.ip ~ '/' ~ iface.prefix
|
||||||
api_host: "{{ hypervisor_cfg.url }}"
|
~ ((',gw=' ~ iface.gateway) if (iface.gateway | default('') | length > 0) else '') -%}
|
||||||
api_user: "{{ hypervisor_cfg.username }}"
|
{%- else -%}
|
||||||
api_password: "{{ hypervisor_cfg.password }}"
|
{%- set val = 'ip=dhcp' -%}
|
||||||
ciuser: "{{ system_cfg.users[0].name }}"
|
{%- endif -%}
|
||||||
cipassword: "{{ system_cfg.users[0].password }}"
|
{%- set _ = out.update({ 'ipconfig' ~ loop.index0: val }) -%}
|
||||||
ciupgrade: false
|
{%- endfor -%}
|
||||||
node: "{{ hypervisor_cfg.host }}"
|
{{ out }}
|
||||||
vmid: "{{ system_cfg.id }}"
|
community.proxmox.proxmox_kvm:
|
||||||
name: "{{ hostname }}"
|
ciuser: "{{ system_cfg.users[0].name }}"
|
||||||
cpu: host
|
cipassword: "{{ system_cfg.users[0].password }}"
|
||||||
cores: "{{ system_cfg.cpus }}"
|
ciupgrade: false
|
||||||
memory: "{{ system_cfg.memory }}"
|
vmid: "{{ system_cfg.id }}"
|
||||||
balloon: "{{ system_cfg.balloon if system_cfg.balloon is defined and system_cfg.balloon | int > 0 else omit }}"
|
name: "{{ hostname }}"
|
||||||
numa_enabled: true
|
cpu: host
|
||||||
hotplug: network,disk
|
cores: "{{ system_cfg.cpus }}"
|
||||||
update: "{{ virtualization_tpm2_enabled | bool }}"
|
memory: "{{ system_cfg.memory }}"
|
||||||
update_unsafe: "{{ virtualization_tpm2_enabled | bool }}"
|
balloon: "{{ system_cfg.balloon if system_cfg.balloon is defined and system_cfg.balloon | int > 0 else omit }}"
|
||||||
bios: ovmf
|
numa_enabled: true
|
||||||
machine: "{{ 'q35' if virtualization_tpm2_enabled | bool else omit }}"
|
hotplug: network,disk
|
||||||
boot: ac
|
update: "{{ virtualization_tpm2_enabled | bool }}"
|
||||||
scsihw: virtio-scsi-single
|
update_unsafe: "{{ virtualization_tpm2_enabled | bool }}"
|
||||||
scsi: "{{ virtualization_proxmox_scsi }}"
|
bios: ovmf
|
||||||
efidisk0:
|
machine: "{{ 'q35' if virtualization_tpm2_enabled | bool else omit }}"
|
||||||
efitype: 4m
|
boot: ac
|
||||||
format: raw
|
scsihw: virtio-scsi-single
|
||||||
pre_enrolled_keys: false
|
scsi: "{{ virtualization_proxmox_scsi }}"
|
||||||
storage: "{{ hypervisor_cfg.storage }}"
|
efidisk0:
|
||||||
tpmstate0: >-
|
efitype: 4m
|
||||||
{{
|
format: raw
|
||||||
{'storage': hypervisor_cfg.storage, 'version': '2.0'}
|
pre_enrolled_keys: false
|
||||||
if virtualization_tpm2_enabled | bool
|
storage: "{{ hypervisor_cfg.storage }}"
|
||||||
else omit
|
tpmstate0: >-
|
||||||
}}
|
{{
|
||||||
ide:
|
{'storage': hypervisor_cfg.storage, 'version': '2.0'}
|
||||||
ide0: "{{ boot_iso }},media=cdrom"
|
if virtualization_tpm2_enabled | bool
|
||||||
ide1: "{{ rhel_iso + ',media=cdrom' if rhel_iso is defined and rhel_iso | length > 0 else omit }}"
|
else omit
|
||||||
ide2: "{{ hypervisor_cfg.storage }}:cloudinit"
|
}}
|
||||||
net: "{{ virtualization_proxmox_net }}"
|
ide:
|
||||||
ipconfig: "{{ virtualization_proxmox_ipconfig }}"
|
ide0: "{{ boot_iso }},media=cdrom"
|
||||||
nameservers: "{{ system_cfg.network.dns.servers if system_cfg.network.dns.servers | length else omit }}"
|
ide1: "{{ rhel_iso + ',media=cdrom' if rhel_iso is defined and rhel_iso | length > 0 else omit }}"
|
||||||
searchdomains: "{{ system_cfg.network.dns.search if system_cfg.network.dns.search | length else omit }}"
|
ide2: "{{ hypervisor_cfg.storage }}:cloudinit"
|
||||||
onboot: true
|
net: "{{ virtualization_proxmox_net }}"
|
||||||
state: present
|
ipconfig: "{{ virtualization_proxmox_ipconfig }}"
|
||||||
no_log: true
|
nameservers: "{{ system_cfg.network.dns.servers if system_cfg.network.dns.servers | length else omit }}"
|
||||||
|
searchdomains: "{{ system_cfg.network.dns.search if system_cfg.network.dns.search | length else omit }}"
|
||||||
|
onboot: true
|
||||||
|
state: present
|
||||||
|
no_log: true
|
||||||
|
|
||||||
- name: Start VM on Proxmox
|
- name: Start VM on Proxmox
|
||||||
delegate_to: localhost
|
community.proxmox.proxmox_kvm:
|
||||||
community.proxmox.proxmox_kvm:
|
name: "{{ hostname }}"
|
||||||
api_host: "{{ hypervisor_cfg.url }}"
|
vmid: "{{ system_cfg.id }}"
|
||||||
api_user: "{{ hypervisor_cfg.username }}"
|
state: started
|
||||||
api_password: "{{ hypervisor_cfg.password }}"
|
no_log: true
|
||||||
node: "{{ hypervisor_cfg.host }}"
|
register: virtualization_proxmox_start_result
|
||||||
name: "{{ hostname }}"
|
|
||||||
vmid: "{{ system_cfg.id }}"
|
|
||||||
state: started
|
|
||||||
no_log: true
|
|
||||||
register: virtualization_proxmox_start_result
|
|
||||||
|
|
||||||
- name: Set VM created fact
|
- name: Set VM created fact
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
virtualization_vm_created_in_run: true
|
virtualization_vm_created_in_run: true
|
||||||
when: virtualization_proxmox_start_result is defined and virtualization_proxmox_start_result.changed | bool
|
when: virtualization_proxmox_start_result is defined and virtualization_proxmox_start_result.changed | bool
|
||||||
|
|||||||
@@ -11,105 +11,109 @@
|
|||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item | to_json }}"
|
label: "{{ item | to_json }}"
|
||||||
|
|
||||||
# community.vmware: full-featured guest management
|
- name: Deploy VM in vCenter
|
||||||
- name: Create VM in vCenter
|
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
vars:
|
module_defaults:
|
||||||
virtualization_vmware_networks: >-
|
community.vmware.vmware_guest:
|
||||||
{%- set ns = namespace(out=[]) -%}
|
hostname: "{{ hypervisor_cfg.url }}"
|
||||||
{%- for iface in system_cfg.network.interfaces -%}
|
username: "{{ hypervisor_cfg.username }}"
|
||||||
{%- set entry = {'name': iface.bridge, 'type': 'dhcp'} -%}
|
password: "{{ hypervisor_cfg.password }}"
|
||||||
{%- if (iface.vlan | default('') | string | length) > 0 -%}
|
validate_certs: "{{ hypervisor_cfg.certs | bool }}"
|
||||||
{%- set entry = entry | combine({'vlan': iface.vlan | int}) -%}
|
datacenter: "{{ hypervisor_cfg.datacenter }}"
|
||||||
{%- endif -%}
|
community.vmware.vmware_guest_tpm:
|
||||||
{%- set ns.out = ns.out + [entry] -%}
|
hostname: "{{ hypervisor_cfg.url }}"
|
||||||
{%- endfor -%}
|
username: "{{ hypervisor_cfg.username }}"
|
||||||
{{ ns.out }}
|
password: "{{ hypervisor_cfg.password }}"
|
||||||
community.vmware.vmware_guest:
|
validate_certs: "{{ hypervisor_cfg.certs | bool }}"
|
||||||
hostname: "{{ hypervisor_cfg.url }}"
|
datacenter: "{{ hypervisor_cfg.datacenter }}"
|
||||||
username: "{{ hypervisor_cfg.username }}"
|
vmware.vmware.vm_powerstate:
|
||||||
password: "{{ hypervisor_cfg.password }}"
|
hostname: "{{ hypervisor_cfg.url }}"
|
||||||
validate_certs: "{{ hypervisor_cfg.certs | bool }}"
|
username: "{{ hypervisor_cfg.username }}"
|
||||||
datacenter: "{{ hypervisor_cfg.datacenter }}"
|
password: "{{ hypervisor_cfg.password }}"
|
||||||
cluster: "{{ hypervisor_cfg.cluster }}"
|
validate_certs: "{{ hypervisor_cfg.certs | bool }}"
|
||||||
folder: "{{ system_cfg.path if system_cfg.path | string | length > 0 else omit }}"
|
datacenter: "{{ hypervisor_cfg.datacenter }}"
|
||||||
name: "{{ hostname }}"
|
block:
|
||||||
# Generic guest ID — VMware auto-detects OS post-install
|
# community.vmware: full-featured guest management
|
||||||
guest_id: otherLinux64Guest
|
- name: Create VM in vCenter
|
||||||
annotation: |
|
vars:
|
||||||
{{ note if note is defined else '' }}
|
virtualization_vmware_networks: >-
|
||||||
state: "{{ 'poweredoff' if virtualization_tpm2_enabled | bool else 'poweredon' }}"
|
{%- set ns = namespace(out=[]) -%}
|
||||||
disk: "{{ virtualization_vmware_disks }}"
|
{%- for iface in system_cfg.network.interfaces -%}
|
||||||
hardware:
|
{%- set entry = {'name': iface.bridge, 'type': 'dhcp'} -%}
|
||||||
memory_mb: "{{ system_cfg.memory }}"
|
{%- if (iface.vlan | default('') | string | length) > 0 -%}
|
||||||
num_cpus: "{{ system_cfg.cpus }}"
|
{%- set entry = entry | combine({'vlan': iface.vlan | int}) -%}
|
||||||
boot_firmware: efi
|
{%- endif -%}
|
||||||
secure_boot: false
|
{%- set ns.out = ns.out + [entry] -%}
|
||||||
cdrom: >-
|
{%- endfor -%}
|
||||||
{{
|
{{ ns.out }}
|
||||||
[ {
|
community.vmware.vmware_guest:
|
||||||
"controller_number": 0,
|
cluster: "{{ hypervisor_cfg.cluster }}"
|
||||||
"unit_number": 0,
|
folder: "{{ system_cfg.path if system_cfg.path | string | length > 0 else omit }}"
|
||||||
"controller_type": "sata",
|
name: "{{ hostname }}"
|
||||||
"state": "present",
|
# Generic guest ID — VMware auto-detects OS post-install
|
||||||
"type": "iso",
|
guest_id: otherLinux64Guest
|
||||||
"iso_path": boot_iso
|
annotation: |
|
||||||
} ]
|
{{ note if note is defined else '' }}
|
||||||
+
|
state: "{{ 'poweredoff' if virtualization_tpm2_enabled | bool else 'poweredon' }}"
|
||||||
( [ {
|
disk: "{{ virtualization_vmware_disks }}"
|
||||||
"controller_number": 0,
|
hardware:
|
||||||
"unit_number": 1,
|
memory_mb: "{{ system_cfg.memory }}"
|
||||||
"controller_type": "sata",
|
num_cpus: "{{ system_cfg.cpus }}"
|
||||||
"state": "present",
|
boot_firmware: efi
|
||||||
"type": "iso",
|
secure_boot: false
|
||||||
"iso_path": rhel_iso
|
cdrom: >-
|
||||||
} ] if rhel_iso is defined and rhel_iso | length > 0 else [] )
|
{{
|
||||||
}}
|
[ {
|
||||||
networks: "{{ virtualization_vmware_networks }}"
|
"controller_number": 0,
|
||||||
no_log: true
|
"unit_number": 0,
|
||||||
register: virtualization_vmware_create_result
|
"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
|
- name: Set VM created fact when VM was powered on during creation
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
virtualization_vm_created_in_run: true
|
virtualization_vm_created_in_run: true
|
||||||
when:
|
when:
|
||||||
- virtualization_vmware_create_result is defined
|
- virtualization_vmware_create_result is defined
|
||||||
- not virtualization_tpm2_enabled | bool
|
- not virtualization_tpm2_enabled | bool
|
||||||
- virtualization_vmware_create_result.changed | bool
|
- virtualization_vmware_create_result.changed | bool
|
||||||
|
|
||||||
- name: Ensure vTPM2 is enabled when required
|
- name: Ensure vTPM2 is enabled when required
|
||||||
when: virtualization_tpm2_enabled | bool
|
when: virtualization_tpm2_enabled | bool
|
||||||
delegate_to: localhost
|
community.vmware.vmware_guest_tpm:
|
||||||
community.vmware.vmware_guest_tpm:
|
folder: "{{ system_cfg.path if system_cfg.path | string | length > 0 else omit }}"
|
||||||
hostname: "{{ hypervisor_cfg.url }}"
|
name: "{{ hostname }}"
|
||||||
username: "{{ hypervisor_cfg.username }}"
|
state: present
|
||||||
password: "{{ hypervisor_cfg.password }}"
|
no_log: true
|
||||||
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
|
|
||||||
|
|
||||||
# vmware.vmware: modern collection for power operations
|
# vmware.vmware: modern collection for power operations
|
||||||
- name: Start VM in vCenter
|
- name: Start VM in vCenter
|
||||||
when: virtualization_tpm2_enabled | bool
|
when: virtualization_tpm2_enabled | bool
|
||||||
delegate_to: localhost
|
vmware.vmware.vm_powerstate:
|
||||||
vmware.vmware.vm_powerstate:
|
name: "{{ hostname }}"
|
||||||
hostname: "{{ hypervisor_cfg.url }}"
|
state: powered-on
|
||||||
username: "{{ hypervisor_cfg.username }}"
|
no_log: true
|
||||||
password: "{{ hypervisor_cfg.password }}"
|
register: virtualization_vmware_start_result
|
||||||
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)
|
- name: Set VM created fact when VM was started separately (TPM2 case)
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
virtualization_vm_created_in_run: true
|
virtualization_vm_created_in_run: true
|
||||||
when:
|
when:
|
||||||
- virtualization_tpm2_enabled | bool
|
- virtualization_tpm2_enabled | bool
|
||||||
- virtualization_vmware_start_result is defined
|
- virtualization_vmware_start_result is defined
|
||||||
- virtualization_vmware_start_result.changed | bool
|
- virtualization_vmware_start_result.changed | bool
|
||||||
|
|||||||
Reference in New Issue
Block a user