diff --git a/roles/cleanup/tasks/proxmox.yml b/roles/cleanup/tasks/proxmox.yml index 57f0181..475ade0 100644 --- a/roles/cleanup/tasks/proxmox.yml +++ b/roles/cleanup/tasks/proxmox.yml @@ -4,15 +4,8 @@ delegate_to: localhost 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 }}" + community.proxmox.proxmox_disk: "{{ _proxmox_auth }}" + community.proxmox.proxmox_kvm: "{{ _proxmox_auth_node }}" block: - name: Cleanup Setup Disks community.proxmox.proxmox_disk: diff --git a/roles/cleanup/tasks/virtual.yml b/roles/cleanup/tasks/virtual.yml index 0c9df8f..2fb56c9 100644 --- a/roles/cleanup/tasks/virtual.yml +++ b/roles/cleanup/tasks/virtual.yml @@ -88,11 +88,7 @@ delegate_to: localhost become: false 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 }}" + community.proxmox.proxmox_kvm: "{{ _proxmox_auth_node }}" no_log: true block: - name: Stop Proxmox VM @@ -113,11 +109,7 @@ delegate_to: localhost 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 }}" + community.vmware.vmware_guest: "{{ _vmware_auth }}" no_log: true block: - name: Power off VMware VM diff --git a/roles/cleanup/tasks/vmware.yml b/roles/cleanup/tasks/vmware.yml index 3dc1ea7..2511f86 100644 --- a/roles/cleanup/tasks/vmware.yml +++ b/roles/cleanup/tasks/vmware.yml @@ -4,18 +4,8 @@ delegate_to: localhost 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 }}" + community.vmware.vmware_guest: "{{ _vmware_auth }}" + vmware.vmware.vm_powerstate: "{{ _vmware_auth }}" no_log: true block: - name: Remove CD-ROM from VM in vCenter diff --git a/roles/global_defaults/tasks/main.yml b/roles/global_defaults/tasks/main.yml index 93008aa..1bcf33f 100644 --- a/roles/global_defaults/tasks/main.yml +++ b/roles/global_defaults/tasks/main.yml @@ -10,6 +10,31 @@ - name: Normalize hypervisor inputs ansible.builtin.include_tasks: hypervisor.yml +- name: Set VMware module auth defaults + when: hypervisor_type == 'vmware' + ansible.builtin.set_fact: + _vmware_auth: + 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 + +- name: Set Proxmox module auth defaults + when: hypervisor_type == 'proxmox' + ansible.builtin.set_fact: + _proxmox_auth: + api_host: "{{ hypervisor_cfg.url }}" + api_user: "{{ hypervisor_cfg.username }}" + api_password: "{{ hypervisor_cfg.password }}" + _proxmox_auth_node: + api_host: "{{ hypervisor_cfg.url }}" + api_user: "{{ hypervisor_cfg.username }}" + api_password: "{{ hypervisor_cfg.password }}" + node: "{{ hypervisor_cfg.host }}" + no_log: true + - name: Normalize system inputs ansible.builtin.include_tasks: system.yml diff --git a/roles/virtualization/tasks/proxmox.yml b/roles/virtualization/tasks/proxmox.yml index c2a64e9..7123f21 100644 --- a/roles/virtualization/tasks/proxmox.yml +++ b/roles/virtualization/tasks/proxmox.yml @@ -2,11 +2,7 @@ - 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 }}" + community.proxmox.proxmox_kvm: "{{ _proxmox_auth_node }}" block: - name: Create VM on Proxmox vars: diff --git a/roles/virtualization/tasks/vmware.yml b/roles/virtualization/tasks/vmware.yml index fd5c0a2..0bc89af 100644 --- a/roles/virtualization/tasks/vmware.yml +++ b/roles/virtualization/tasks/vmware.yml @@ -14,24 +14,9 @@ - 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 }}" + community.vmware.vmware_guest: "{{ _vmware_auth }}" + community.vmware.vmware_guest_tpm: "{{ _vmware_auth }}" + vmware.vmware.vm_powerstate: "{{ _vmware_auth }}" block: # community.vmware: full-featured guest management - name: Create VM in vCenter