refactor(virt): adopt module_defaults for hypervisor credentials
This commit is contained in:
@@ -3,12 +3,20 @@
|
||||
when: hypervisor_type == "proxmox"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
block:
|
||||
- name: Cleanup Setup Disks
|
||||
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:
|
||||
- name: Cleanup Setup Disks
|
||||
community.proxmox.proxmox_disk:
|
||||
name: "{{ hostname }}"
|
||||
vmid: "{{ system_cfg.id }}"
|
||||
disk: "{{ item }}"
|
||||
@@ -17,14 +25,8 @@
|
||||
- ide0
|
||||
- ide2
|
||||
failed_when: false
|
||||
no_log: true
|
||||
|
||||
- name: Start the VM
|
||||
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 }}"
|
||||
state: restarted
|
||||
no_log: true
|
||||
|
||||
@@ -3,14 +3,23 @@
|
||||
when: hypervisor_type == "vmware"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
block:
|
||||
- name: Remove CD-ROM from VM in vCenter
|
||||
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:
|
||||
- name: Remove CD-ROM from VM in vCenter
|
||||
community.vmware.vmware_guest:
|
||||
name: "{{ hostname }}"
|
||||
cdrom: >-
|
||||
{{
|
||||
@@ -40,15 +49,8 @@
|
||||
)
|
||||
}}
|
||||
failed_when: false
|
||||
no_log: true
|
||||
|
||||
- name: Start VM in vCenter
|
||||
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
|
||||
|
||||
@@ -33,24 +33,27 @@
|
||||
Please choose a different hostname or remove the existing VM manually before proceeding.
|
||||
quiet: true
|
||||
|
||||
- name: Check if VM already exists on Proxmox
|
||||
- name: Check VM existence on Proxmox
|
||||
when: hypervisor_type == "proxmox"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
module_defaults:
|
||||
community.proxmox.proxmox_vm_info:
|
||||
api_host: "{{ hypervisor_cfg.url }}"
|
||||
api_user: "{{ hypervisor_cfg.username }}"
|
||||
api_password: "{{ hypervisor_cfg.password }}"
|
||||
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
|
||||
no_log: true
|
||||
|
||||
- name: Abort if VM already exists on Proxmox
|
||||
when: hypervisor_type == "proxmox"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_check_proxmox_check_result.proxmox_vms | default([]) | length == 0
|
||||
@@ -60,24 +63,27 @@
|
||||
Please choose a different hostname or VM ID, or remove the existing VM manually before proceeding.
|
||||
quiet: true
|
||||
|
||||
- name: Check if VM already exists in vCenter
|
||||
- name: Check VM existence in vCenter
|
||||
when: hypervisor_type == "vmware"
|
||||
delegate_to: localhost
|
||||
module_defaults:
|
||||
community.vmware.vmware_guest_info:
|
||||
hostname: "{{ hypervisor_cfg.url }}"
|
||||
username: "{{ hypervisor_cfg.username }}"
|
||||
password: "{{ hypervisor_cfg.password }}"
|
||||
validate_certs: "{{ hypervisor_cfg.certs | bool }}"
|
||||
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
|
||||
no_log: true
|
||||
|
||||
- name: Fail if vCenter lookup failed unexpectedly
|
||||
when: hypervisor_type == "vmware"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- not system_check_vmware_check_result.failed
|
||||
@@ -88,7 +94,6 @@
|
||||
quiet: true
|
||||
|
||||
- name: Abort if VM already exists in vCenter
|
||||
when: hypervisor_type == "vmware"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- system_check_vmware_check_result.instance is not defined
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
---
|
||||
- name: Deploy VM on Proxmox
|
||||
delegate_to: localhost
|
||||
module_defaults:
|
||||
community.proxmox.proxmox_kvm:
|
||||
api_host: "{{ hypervisor_cfg.url }}"
|
||||
api_user: "{{ hypervisor_cfg.username }}"
|
||||
api_password: "{{ hypervisor_cfg.password }}"
|
||||
node: "{{ hypervisor_cfg.host }}"
|
||||
block:
|
||||
- name: Create VM on Proxmox
|
||||
vars:
|
||||
virtualization_proxmox_scsi: >-
|
||||
{%- set out = {} -%}
|
||||
@@ -31,13 +39,9 @@
|
||||
{%- endfor -%}
|
||||
{{ out }}
|
||||
community.proxmox.proxmox_kvm:
|
||||
api_host: "{{ hypervisor_cfg.url }}"
|
||||
api_user: "{{ hypervisor_cfg.username }}"
|
||||
api_password: "{{ hypervisor_cfg.password }}"
|
||||
ciuser: "{{ system_cfg.users[0].name }}"
|
||||
cipassword: "{{ system_cfg.users[0].password }}"
|
||||
ciupgrade: false
|
||||
node: "{{ hypervisor_cfg.host }}"
|
||||
vmid: "{{ system_cfg.id }}"
|
||||
name: "{{ hostname }}"
|
||||
cpu: host
|
||||
@@ -77,12 +81,7 @@
|
||||
no_log: true
|
||||
|
||||
- name: Start VM on Proxmox
|
||||
delegate_to: localhost
|
||||
community.proxmox.proxmox_kvm:
|
||||
api_host: "{{ hypervisor_cfg.url }}"
|
||||
api_user: "{{ hypervisor_cfg.username }}"
|
||||
api_password: "{{ hypervisor_cfg.password }}"
|
||||
node: "{{ hypervisor_cfg.host }}"
|
||||
name: "{{ hostname }}"
|
||||
vmid: "{{ system_cfg.id }}"
|
||||
state: started
|
||||
|
||||
@@ -11,9 +11,30 @@
|
||||
loop_control:
|
||||
label: "{{ item | to_json }}"
|
||||
|
||||
- name: Deploy VM in vCenter
|
||||
delegate_to: localhost
|
||||
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 }}"
|
||||
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 }}"
|
||||
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 }}"
|
||||
block:
|
||||
# community.vmware: full-featured guest management
|
||||
- name: Create VM in vCenter
|
||||
delegate_to: localhost
|
||||
vars:
|
||||
virtualization_vmware_networks: >-
|
||||
{%- set ns = namespace(out=[]) -%}
|
||||
@@ -26,11 +47,6 @@
|
||||
{%- 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 }}"
|
||||
@@ -79,13 +95,7 @@
|
||||
|
||||
- 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
|
||||
@@ -94,13 +104,7 @@
|
||||
# vmware.vmware: modern collection for power operations
|
||||
- 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
|
||||
|
||||
Reference in New Issue
Block a user