From 096220d49caadf7007ffeeace39845c3a968cd09 Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Wed, 23 Apr 2025 17:51:03 +0200 Subject: [PATCH 01/12] Prepare integration tests: Substitute vmware.vmware_rest.vcenter_datacenter_info --- .../prepare_vmware_tests/tasks/teardown.yml | 15 ++++++++++----- .../tasks/teardown_with_esxi.yml | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown.yml index b5e42118da..dfe47fb2cc 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown.yml @@ -1,11 +1,16 @@ --- - name: Get a list of all the datacenters - vmware.vmware_rest.vcenter_datacenter_info: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false + community.vmware.vmware_datacenter_info: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false register: existing_datacenters + +- name: Debug datacenters + debug: + var: existing_datacenters + - name: Force delete the existing DC vmware.vmware_rest.vcenter_datacenter: vcenter_hostname: '{{ vcenter_hostname }}' diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml index db4c165de0..44deb1cf7a 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -72,12 +72,17 @@ with_items: "{{ result.value }}" - name: Get a list of all the datacenters - vmware.vmware_rest.vcenter_datacenter_info: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false + community.vmware.vmware_datacenter_info: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false register: existing_datacenters + +- name: Debug datacenters + debug: + var: existing_datacenters + - name: Force delete the existing DC vmware.vmware_rest.vcenter_datacenter: vcenter_hostname: '{{ vcenter_hostname }}' From f3e6ba92202690a0c83f23abf476d8dcd5fd9531 Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Wed, 23 Apr 2025 19:32:30 +0200 Subject: [PATCH 02/12] Prepare integration tests: Substitute vmware.vmware_rest.vcenter_datacenter --- .../prepare_vmware_tests/tasks/teardown.yml | 19 +++++++------------ .../tasks/teardown_with_esxi.yml | 19 +++++++------------ 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown.yml index dfe47fb2cc..ee8951c99a 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown.yml @@ -7,20 +7,15 @@ validate_certs: false register: existing_datacenters -- name: Debug datacenters - debug: - var: existing_datacenters - - name: Force delete the existing DC - vmware.vmware_rest.vcenter_datacenter: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false + community.vmware.vmware_datacenter: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + datacenter_name: '{{ item.name }}' state: absent - datacenter: '{{ item.datacenter }}' - force: true - with_items: "{{ existing_datacenters.value }}" + with_items: "{{ existing_datacenters.datacenter_info }}" until: _result is succeeded retries: 10 delay: 1 diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml index 44deb1cf7a..d91744309a 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -79,20 +79,15 @@ validate_certs: false register: existing_datacenters -- name: Debug datacenters - debug: - var: existing_datacenters - - name: Force delete the existing DC - vmware.vmware_rest.vcenter_datacenter: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false + community.vmware.vmware_datacenter: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + datacenter_name: '{{ item.name }}' state: absent - datacenter: '{{ item.datacenter }}' - force: true - with_items: "{{ existing_datacenters.value }}" + with_items: "{{ existing_datacenters.datacenter_info }}" until: _result is succeeded retries: 10 delay: 1 From 33f656ce4650040b96aefd1f83b6524868fa249c Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Fri, 25 Apr 2025 16:11:05 +0200 Subject: [PATCH 03/12] Replace vmware.vmware_rest.vcenter_vm_info --- .../tasks/teardown_with_esxi.yml | 13 ++++++++----- .../vmware_guest/tasks/run_test_playbook.yml | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml index d91744309a..001af2104c 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -1,10 +1,13 @@ --- - name: Collect the list of the existing VM - vmware.vmware_rest.vcenter_vm_info: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false + vmware.vmware.guest_info: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + schema: vsphere + properties: + - _moId register: existing_vms until: existing_vms is not failed diff --git a/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml b/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml index 07f9230e7e..60b05c060c 100644 --- a/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml +++ b/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml @@ -2,11 +2,14 @@ - include_tasks: '{{ test_playbook }}' always: - name: Collect the list of the existing VM - vmware.vmware_rest.vcenter_vm_info: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false + vmware.vmware.guest_info: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + schema: vsphere + properties: + - _moId register: existing_vms until: existing_vms is not failed - name: Turn off the VM From 2d1cdb90cac82bb7299cc79b124999f613de6d15 Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Fri, 25 Apr 2025 16:44:43 +0200 Subject: [PATCH 04/12] Replace vmware.vmware_rest.vcenter_vm_power --- .../tasks/teardown_with_esxi.yml | 16 ++++++++-------- .../vmware_guest/tasks/run_test_playbook.yml | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml index 001af2104c..4d31223ecf 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -12,14 +12,14 @@ until: existing_vms is not failed - name: Turn off the VM - vmware.vmware_rest.vcenter_vm_power: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false - state: stop - vm: '{{ item.vm }}' - with_items: "{{ existing_vms.value }}" + vmware.vmware.vm_powerstate: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + state: powered-off + moid: '{{ item.moid }}' + with_items: "{{ existing_vms.guests }}" ignore_errors: true - name: Delete the VMs diff --git a/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml b/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml index 60b05c060c..9558fac9bb 100644 --- a/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml +++ b/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml @@ -13,14 +13,14 @@ register: existing_vms until: existing_vms is not failed - name: Turn off the VM - vmware.vmware_rest.vcenter_vm_power: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false - state: stop - vm: '{{ item.vm }}' - with_items: "{{ existing_vms.value }}" + vmware.vmware.vm_powerstate: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + state: powered-off + moid: '{{ item.moid }}' + with_items: "{{ existing_vms.guests }}" ignore_errors: true - name: Clean up VM vmware.vmware_rest.vcenter_vm: From a914a2385690368619489a6dc2d68b24c8dfcb1a Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Fri, 25 Apr 2025 17:57:05 +0200 Subject: [PATCH 05/12] Replace vmware.vmware_rest.vcenter_vm --- .../tasks/teardown_with_esxi.yml | 25 ++++++------------- .../vmware_guest/tasks/run_test_playbook.yml | 22 ++++++---------- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml index 4d31223ecf..eed50b9b2e 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -7,34 +7,25 @@ validate_certs: false schema: vsphere properties: - - _moId + - config.instanceUuid + - name register: existing_vms until: existing_vms is not failed -- name: Turn off the VM - vmware.vmware.vm_powerstate: +- name: Delete the VMs + community.vmware.vmware_guest: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' validate_certs: false - state: powered-off - moid: '{{ item.moid }}' - with_items: "{{ existing_vms.guests }}" - ignore_errors: true - -- name: Delete the VMs - vmware.vmware_rest.vcenter_vm: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false + uuid: '{{ item.config.instanceUuid }}' state: absent - vm: '{{ item.vm }}' - with_items: "{{ existing_vms.value }}" + force: true + delete_from_inventory: true + with_items: "{{ existing_vms.guests }}" when: - not item.name.startswith("vCLS") - - name: Build a list of local libraries vmware.vmware_rest.content_locallibrary_info: vcenter_hostname: '{{ vcenter_hostname }}' diff --git a/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml b/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml index 9558fac9bb..a436f1d71a 100644 --- a/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml +++ b/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml @@ -9,27 +9,21 @@ validate_certs: false schema: vsphere properties: - - _moId + - config.instanceUuid + - name register: existing_vms until: existing_vms is not failed - - name: Turn off the VM - vmware.vmware.vm_powerstate: + - name: Clean up VM + community.vmware.vmware_guest: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' validate_certs: false - state: powered-off - moid: '{{ item.moid }}' + uuid: '{{ item.config.instanceUuid }}' + state: absent + force: true + delete_from_inventory: true with_items: "{{ existing_vms.guests }}" ignore_errors: true - - name: Clean up VM - vmware.vmware_rest.vcenter_vm: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false - state: absent - vm: '{{ item.vm }}' - with_items: "{{ existing_vms.value }}" when: - not item.name.startswith("vCLS") From 90b5a0273546f458e3a423d725e298074810ce8c Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Sun, 27 Apr 2025 14:33:05 +0200 Subject: [PATCH 06/12] Turn off the VM again --- .../tasks/teardown_with_esxi.yml | 14 ++++++++++++++ .../vmware_guest/tasks/run_test_playbook.yml | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml index eed50b9b2e..13644b5559 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -12,6 +12,20 @@ register: existing_vms until: existing_vms is not failed +- name: Turn off the VM + community.vmware.vmware_guest_powerstate: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + uuid: '{{ item.config.instanceUuid }}' + state: powered-off + force: true + use_instance_uuid: true + with_items: "{{ existing_vms.guests }}" + when: + - not item.name.startswith("vCLS") + - name: Delete the VMs community.vmware.vmware_guest: hostname: '{{ vcenter_hostname }}' diff --git a/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml b/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml index a436f1d71a..d85e6e8d4c 100644 --- a/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml +++ b/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml @@ -13,6 +13,19 @@ - name register: existing_vms until: existing_vms is not failed + - name: Turn off the VM + community.vmware.vmware_guest_powerstate: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + uuid: '{{ item.config.instanceUuid }}' + state: powered-off + force: true + use_instance_uuid: true + with_items: "{{ existing_vms.guests }}" + when: + - not item.name.startswith("vCLS") - name: Clean up VM community.vmware.vmware_guest: hostname: '{{ vcenter_hostname }}' From c4eeb494d4153b05006704b1321694935bafc174 Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Tue, 29 Apr 2025 16:31:56 +0200 Subject: [PATCH 07/12] Use instance UUID --- .../targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml | 1 + .../integration/targets/vmware_guest/tasks/run_test_playbook.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml index 13644b5559..b3ee9a53e4 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -36,6 +36,7 @@ state: absent force: true delete_from_inventory: true + use_instance_uuid: true with_items: "{{ existing_vms.guests }}" when: - not item.name.startswith("vCLS") diff --git a/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml b/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml index d85e6e8d4c..d8257d16d3 100644 --- a/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml +++ b/tests/integration/targets/vmware_guest/tasks/run_test_playbook.yml @@ -36,6 +36,7 @@ state: absent force: true delete_from_inventory: true + use_instance_uuid: true with_items: "{{ existing_vms.guests }}" ignore_errors: true when: From 55ceb46cafcb6b435f7141084047278ffa48683b Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Tue, 29 Apr 2025 16:33:36 +0200 Subject: [PATCH 08/12] Replace vmware.vmware_rest content library modules --- .../tasks/teardown_with_esxi.yml | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml index b3ee9a53e4..3806fb21eb 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -41,44 +41,43 @@ when: - not item.name.startswith("vCLS") -- name: Build a list of local libraries - vmware.vmware_rest.content_locallibrary_info: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false +- name: Build a list of libraries + community.vmware.vmware_content_library_info: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false register: result retries: 100 delay: 3 until: result is not failed -- name: Delete all the local libraries - vmware.vmware_rest.content_locallibrary: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false - library_id: "{{ item.id }}" - state: absent - with_items: "{{ result.value }}" +- debug: + var: result -- name: Build a list of subscribed libraries - vmware.vmware_rest.content_subscribedlibrary_info: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false - register: result +- name: Delete all libraries + block: + - name: Get library details + community.vmware.vmware_content_library_info: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + library_id: "{{ item }}" + register: lib_result -- name: Delete all the subscribed libraries - vmware.vmware_rest.content_subscribedlibrary: - vcenter_hostname: '{{ vcenter_hostname }}' - vcenter_username: '{{ vcenter_username }}' - vcenter_password: '{{ vcenter_password }}' - vcenter_validate_certs: false - library_id: "{{ item.id }}" - state: absent - with_items: "{{ result.value }}" + - debug: + var: item + + - name: Delete library + community.vmware.vmware_content_library_manager: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + library_name: "{{ lib_result.library_name }}" + state: absent + with_items: "{{ result }}" - name: Get a list of all the datacenters community.vmware.vmware_datacenter_info: From 25015e1aecb2f0114cb25f4e39e3f8517b0377c8 Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Wed, 30 Apr 2025 17:52:05 +0200 Subject: [PATCH 09/12] Drop with_items from block --- .../targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml index 3806fb21eb..e61075fb00 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -77,7 +77,6 @@ validate_certs: false library_name: "{{ lib_result.library_name }}" state: absent - with_items: "{{ result }}" - name: Get a list of all the datacenters community.vmware.vmware_datacenter_info: From 2815580328ebf2e2e1f21f0004bb73607aac1255 Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Wed, 30 Apr 2025 18:23:14 +0200 Subject: [PATCH 10/12] Remove Delete all libraries block --- .../tasks/teardown_with_esxi.yml | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml index e61075fb00..8c97e7ee9e 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -55,28 +55,15 @@ - debug: var: result -- name: Delete all libraries - block: - - name: Get library details - community.vmware.vmware_content_library_info: - hostname: '{{ vcenter_hostname }}' - username: '{{ vcenter_username }}' - password: '{{ vcenter_password }}' - validate_certs: false - library_id: "{{ item }}" - register: lib_result - - - debug: - var: item - - - name: Delete library - community.vmware.vmware_content_library_manager: - hostname: '{{ vcenter_hostname }}' - username: '{{ vcenter_username }}' - password: '{{ vcenter_password }}' - validate_certs: false - library_name: "{{ lib_result.library_name }}" - state: absent +- name: Delete library + community.vmware.vmware_content_library_manager: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + library_name: "{{ lib_result.library_name }}" + state: absent + with_items: "{{ result.content_libs }}" - name: Get a list of all the datacenters community.vmware.vmware_datacenter_info: From 3855a65fa644855d339b84286496d5f301fc32d8 Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Wed, 30 Apr 2025 19:47:17 +0200 Subject: [PATCH 11/12] Temporarily disable inventory integration tests --- .../inventory_vmware_host_inventory/aliases | 3 - .../playbook/build_inventory.yml | 23 -- .../playbook/build_inventory_with_cache.yml | 14 - .../build_inventory_without_cache.yml | 14 - .../playbook/install_dependencies.yml | 7 - .../playbook/prepare_vmware.yml | 17 - .../playbook/test_inventory_cache.yml | 51 --- .../playbook/test_options.yml | 211 ----------- .../playbook/test_vmware_host_inventory.yml | 18 - .../inventory_vmware_host_inventory/runme.sh | 56 --- .../inventory_vmware_vm_inventory/aliases | 2 - .../playbook/build_inventory.yml | 20 -- .../playbook/build_inventory_with_cache.yml | 11 - .../build_inventory_without_cache.yml | 12 - .../playbook/install_dependencies.yml | 7 - .../playbook/prepare_vmware.yml | 18 - .../playbook/test_inventory_cache.yml | 51 --- .../playbook/test_options.yml | 332 ------------------ .../playbook/test_vmware_vm_inventory.yml | 18 - .../inventory_vmware_vm_inventory/runme.sh | 56 --- .../targets/vmware_vm_inventory/aliases | 2 - .../targets/vmware_vm_inventory/ansible.cfg | 9 - .../prepare_environment.yml | 57 --- .../targets/vmware_vm_inventory/runme.sh | 7 - .../vmware_vm_inventory/test_inventory.yml | 10 - 25 files changed, 1026 deletions(-) delete mode 100644 tests/integration/targets/inventory_vmware_host_inventory/aliases delete mode 100644 tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory.yml delete mode 100644 tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory_with_cache.yml delete mode 100644 tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory_without_cache.yml delete mode 100644 tests/integration/targets/inventory_vmware_host_inventory/playbook/install_dependencies.yml delete mode 100644 tests/integration/targets/inventory_vmware_host_inventory/playbook/prepare_vmware.yml delete mode 100644 tests/integration/targets/inventory_vmware_host_inventory/playbook/test_inventory_cache.yml delete mode 100644 tests/integration/targets/inventory_vmware_host_inventory/playbook/test_options.yml delete mode 100644 tests/integration/targets/inventory_vmware_host_inventory/playbook/test_vmware_host_inventory.yml delete mode 100755 tests/integration/targets/inventory_vmware_host_inventory/runme.sh delete mode 100644 tests/integration/targets/inventory_vmware_vm_inventory/aliases delete mode 100644 tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory.yml delete mode 100644 tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory_with_cache.yml delete mode 100644 tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory_without_cache.yml delete mode 100644 tests/integration/targets/inventory_vmware_vm_inventory/playbook/install_dependencies.yml delete mode 100644 tests/integration/targets/inventory_vmware_vm_inventory/playbook/prepare_vmware.yml delete mode 100644 tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_inventory_cache.yml delete mode 100644 tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_options.yml delete mode 100644 tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_vmware_vm_inventory.yml delete mode 100755 tests/integration/targets/inventory_vmware_vm_inventory/runme.sh delete mode 100644 tests/integration/targets/vmware_vm_inventory/aliases delete mode 100644 tests/integration/targets/vmware_vm_inventory/ansible.cfg delete mode 100644 tests/integration/targets/vmware_vm_inventory/prepare_environment.yml delete mode 100755 tests/integration/targets/vmware_vm_inventory/runme.sh delete mode 100644 tests/integration/targets/vmware_vm_inventory/test_inventory.yml diff --git a/tests/integration/targets/inventory_vmware_host_inventory/aliases b/tests/integration/targets/inventory_vmware_host_inventory/aliases deleted file mode 100644 index 07e8732a30..0000000000 --- a/tests/integration/targets/inventory_vmware_host_inventory/aliases +++ /dev/null @@ -1,3 +0,0 @@ -cloud/vcenter -needs/target/prepare_vmware_tests -zuul/vmware/vcenter_1esxi diff --git a/tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory.yml b/tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory.yml deleted file mode 100644 index 1479778cca..0000000000 --- a/tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- - - name: Set inventory content - copy: - dest: "{{ lookup('env', 'INVENTORY_DIR') }}/tmp.vmware.yml" - content: | - {{ content }} - hostname: '{{ vcenter_hostname }}' - username: '{{ vcenter_username }}' - password: '{{ vcenter_password }}' - port: '{{ vcenter_port|default('443') }}' - validate_certs: {{ vmware_validate_certs|default('no') }} - changed_when: false - check_mode: false - - - meta: refresh_inventory - - - debug: - msg: "{{ hostvars }}" - - - name: Refresh test_host - set_fact: - test_host: "{{ hostvars | dict2items | first }}" - when: hostvars | length >= 1 \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory_with_cache.yml b/tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory_with_cache.yml deleted file mode 100644 index 1fcb0cda28..0000000000 --- a/tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory_with_cache.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- hosts: localhost - tasks: - - name: Inventory with 'cache' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: false - cache: true - properties: - - name - - summary.runtime.powerState - - customValue diff --git a/tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory_without_cache.yml b/tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory_without_cache.yml deleted file mode 100644 index 4b50b26e0c..0000000000 --- a/tests/integration/targets/inventory_vmware_host_inventory/playbook/build_inventory_without_cache.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- hosts: localhost - tasks: - - name: Inventory without 'cache' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: true - cache: false - properties: - - name - - summary.runtime.powerState - - customValue diff --git a/tests/integration/targets/inventory_vmware_host_inventory/playbook/install_dependencies.yml b/tests/integration/targets/inventory_vmware_host_inventory/playbook/install_dependencies.yml deleted file mode 100644 index d3aab8c60f..0000000000 --- a/tests/integration/targets/inventory_vmware_host_inventory/playbook/install_dependencies.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: Install dependencies - hosts: localhost - gather_facts: false - tasks: - - pip: - name: toml \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_host_inventory/playbook/prepare_vmware.yml b/tests/integration/targets/inventory_vmware_host_inventory/playbook/prepare_vmware.yml deleted file mode 100644 index 921edb43be..0000000000 --- a/tests/integration/targets/inventory_vmware_host_inventory/playbook/prepare_vmware.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- name: Prepare VMware folders for testing dynamic inventory folder support - hosts: localhost - gather_facts: false - module_defaults: - group/vmware: - hostname: '{{ vcenter_hostname }}' - username: '{{ vcenter_username }}' - password: '{{ vcenter_password }}' - port: "{{ vcenter_port|default('443') }}" - validate_certs: "{{ vmware_validate_certs|default('no') }}" - tasks: - - import_role: - name: ../prepare_vmware_tests - vars: - setup_attach_host: true - setup_datastore: true \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_host_inventory/playbook/test_inventory_cache.yml b/tests/integration/targets/inventory_vmware_host_inventory/playbook/test_inventory_cache.yml deleted file mode 100644 index 2fd597c587..0000000000 --- a/tests/integration/targets/inventory_vmware_host_inventory/playbook/test_inventory_cache.yml +++ /dev/null @@ -1,51 +0,0 @@ ---- -- name: Test inventory cache - hosts: localhost - gather_facts: false - tasks: - - find: - paths: "{{ lookup('env', 'ANSIBLE_CACHE_PLUGIN_CONNECTION') }}" - patterns: "community.vmware.vmware_host_inventory*" - register: result - - - name: Cache directory exist - fail: - msg: Cache not found. Please debug. - when: result.matched|int == 0 - ignore_errors: true - - - when: result.matched|int == 0 - meta: end_play - - - set_fact: - cached_groups: "{{groups}}" - cached_hostvars: "{{hostvars}}" - - - meta: refresh_inventory - - - name: 'Compare groups' - fail: - msg: "{{ item.key }} not found in cached groups. Please debug." - when: cached_groups[item.key] is not defined - loop: "{{ q('dict', groups) }}" - loop_control: - label: "{{ item.key }}" - - - name: 'Compare hosts' - fail: - msg: "{{ item.key }} not found in cached hosts. Please debug." - when: cached_hostvars[item.key] is not defined - loop: "{{ q('dict', hostvars) }}" - loop_control: - label: "{{ item.key }}" - - - set_fact: - test_host: "{{ hostvars | dict2items | first }}" - - - name: 'Compare hostvars' - fail: - msg: "{{ item.key }} not found in cached hostvars. Please debug." - when: cached_hostvars[test_host.key][item.key] is not defined - loop: "{{ q('dict', test_host.value) }}" - loop_control: - label: "{{ item.key }}" \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_host_inventory/playbook/test_options.yml b/tests/integration/targets/inventory_vmware_host_inventory/playbook/test_options.yml deleted file mode 100644 index 3289ae959e..0000000000 --- a/tests/integration/targets/inventory_vmware_host_inventory/playbook/test_options.yml +++ /dev/null @@ -1,211 +0,0 @@ ---- -- name: Test Hostnames option - hosts: localhost - tasks: - - name: Inventory with 'hostnames' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: false - with_nested_properties: false - properties: - - runtime.powerState - hostnames: - - 'skip_undefined_empty_none_var' - - 'runtime.powerState' - - - name: Test properties option are populate - assert: - that: - - "'runtime.powerState' in test_host.value" - - - name: Test hostnames option - assert: - that: - - test_host.key == (test_host.value['runtime.powerState']) - - - name: Inventory with 'config' root properties - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: false - with_nested_properties: false - properties: - - config.lockdownMode - - name - - summary - - name: Test properties(config) option are populate - assert: - that: - - "'name' in test_host.value" - - "'summary.runtime.powerState' in test_host.value" - - "'config.lockdownMode' in test_host.value" - - - name: Inventory with 'with_path' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: false - with_path: true - properties: - - name - - summary.runtime.powerState - - name: Test path option - assert: - that: - - "'path' in test_host.value" - - - name: Inventory with rooted 'with_path' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: false - with_path: my_center - - name: Test path option with rooted path - assert: - that: - - "'path' in test_host.value" - - "'my_center' in test_host.value.group_names" - - - name: Inventory 'with_nested_properties' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: false - properties: - - name - - summary.runtime.powerState - - config.lockdownMode - with_nested_properties: true - - name: Test 'with_nested_properties' option - assert: - that: - - test_host.value.config.lockdownMode is defined - - - - name: Inventory 'sanitize_property_name' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: false - properties: - - name - - summary.runtime.powerState - - config.lockdownMode - with_sanitized_property_name: true - - name: Test 'with_nested_properties' option - assert: - that: - - test_host.value.config_lockdown_mode is defined - - - - name: Inventory 'Constructable' options - keyed_groups - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: false - with_nested_properties: true - properties: - - name - - summary.runtime.powerState - - config.lockdownMode - keyed_groups: - - key: 'config.lockdownMode' - separator: '' - - name: Test 'Constructable' options - keyed_groups - assert: - that: - - "'lockdownDisabled' in test_host.value.group_names" - - - - name: Inventory filters options - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: false - with_nested_properties: true - properties: - - name - - summary.runtime.powerState - filters: - - summary.runtime.powerState == "poweredOn" - - - debug: - msg: "{{ test_host.value.groups }}" - - - name: Test filters options - assert: - that: - - "test_host.key in test_host.value.groups.all" - - - - name: Inventory 'Constructable' options - compose, groups - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: false - with_nested_properties: true - properties: - - name - - summary.runtime.powerState - compose: - ansible_host: 'name' - composed_var: 'name' - groups: - my_hosts: true - - name: Test 'Constructable' options - compose, groups - assert: - that: - - "'my_hosts' in test_host.value.group_names" - - "'ansible_host' in test_host.value" - - "'composed_var' in test_host.value" - - test_host.value.composed_var == test_host.value.name - - - - name: Inventory 'with_tag' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_host_inventory - strict: false - with_nested_properties: true - with_tags: true - properties: - - name - - summary.runtime.powerState - - name: Test 'with_tags' options - assert: - that: - - "'tags' in test_host.value" - - "'categories' in test_host.value" - - "'tag_category' in test_host.value" - - -# TODO enable again -# https://forum.ansible.com/t/11073 -# https://github.com/ansible-collections/community.vmware/issues/2257 -# - name: Inventory 'resources' option -# include_tasks: build_inventory.yml -# vars: -# content: |- -# plugin: community.vmware.vmware_host_inventory -# strict: false -# resources: -# - datacenter: -# - DC0 -# resources: -# - compute_resource: -# - DC0_C0_NOT_EXIST -# - name: Test 'resources' options with 'DC0_C0_NOT_EXIST' -# assert: -# that: -# - hostvars | length == 0 diff --git a/tests/integration/targets/inventory_vmware_host_inventory/playbook/test_vmware_host_inventory.yml b/tests/integration/targets/inventory_vmware_host_inventory/playbook/test_vmware_host_inventory.yml deleted file mode 100644 index 39950aceaf..0000000000 --- a/tests/integration/targets/inventory_vmware_host_inventory/playbook/test_vmware_host_inventory.yml +++ /dev/null @@ -1,18 +0,0 @@ -# Test code for the vmware host dynamic plugin module -# Copyright: (c) 2021, Abhijeet Kasurde -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - ---- -- name: Test VMware Host Dynamic Inventory Plugin - hosts: localhost - tasks: - - name: Check that there is 'all' group present in inventory - assert: - that: - - "'all' in groups" - - - name: Check if Hostname and other details are populated in hostvars - assert: - that: - - hostvars[item].name is defined - with_items: "{{ groups['all'] }}" \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_host_inventory/runme.sh b/tests/integration/targets/inventory_vmware_host_inventory/runme.sh deleted file mode 100755 index 62915a3f8d..0000000000 --- a/tests/integration/targets/inventory_vmware_host_inventory/runme.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash -set -eux - -# Envs -export ANSIBLE_PYTHON_INTERPRETER=${ANSIBLE_TEST_PYTHON_INTERPRETER:-$(command -v python)} -export ANSIBLE_INVENTORY_ENABLED="community.vmware.vmware_host_inventory,host_list,ini" -export ANSIBLE_CACHE_PLUGIN_CONNECTION="${PWD}/inventory_cache" -export ANSIBLE_CACHE_PLUGIN="jsonfile" - -export INVENTORY_DIR="${PWD}/_test/hosts" -mkdir -p "${INVENTORY_DIR}" 2>/dev/null -touch "${INVENTORY_DIR}/empty.vmware.yml" - -cleanup() { - echo "Cleanup" - if [ -d "${ANSIBLE_CACHE_PLUGIN_CONNECTION}" ]; then - echo "Removing ${ANSIBLE_CACHE_PLUGIN_CONNECTION}" - rm -rf "${ANSIBLE_CACHE_PLUGIN_CONNECTION}" - fi - - if [ -d "${INVENTORY_DIR}" ]; then - echo "Removing ${INVENTORY_DIR}" - rm -rf "${INVENTORY_DIR}" - fi - - unset ANSIBLE_INVENTORY_ENABLED - unset ANSIBLE_CACHE_PLUGIN ANSIBLE_CACHE_PLUGIN_CONNECTION - unset INVENTORY_DIR - - echo "Done" -} - -trap cleanup INT TERM EXIT - -# Prepare tests -ansible-playbook playbook/prepare_vmware.yml "$@" - -# Test Cache -# Cache requires jsonfile -# ansible-playbook playbook/build_inventory_with_cache.yml "$@" -# ansible-inventory -i "${INVENTORY_DIR}" --list -# ansible-playbook -i "${INVENTORY_DIR}" playbook/test_inventory_cache.yml "$@" - -# Test YAML and TOML -ansible-playbook playbook/install_dependencies.yml "$@" -ansible-playbook playbook/build_inventory_without_cache.yml "$@" -ansible-inventory -i "${INVENTORY_DIR}" --list --yaml 1>/dev/null -if ${ANSIBLE_PYTHON_INTERPRETER} -m pip list 2>/dev/null | grep toml >/dev/null 2>&1; then - ansible-inventory -i "${INVENTORY_DIR}" --list --toml 1>/dev/null -fi - -# Test playbook with the given inventory -ansible-playbook -i "${INVENTORY_DIR}" playbook/test_vmware_host_inventory.yml "$@" - -# Test options -ansible-playbook -i "${INVENTORY_DIR}" playbook/test_options.yml "$@" diff --git a/tests/integration/targets/inventory_vmware_vm_inventory/aliases b/tests/integration/targets/inventory_vmware_vm_inventory/aliases deleted file mode 100644 index ad593838d3..0000000000 --- a/tests/integration/targets/inventory_vmware_vm_inventory/aliases +++ /dev/null @@ -1,2 +0,0 @@ -cloud/vcenter -needs/target/prepare_vmware_tests diff --git a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory.yml b/tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory.yml deleted file mode 100644 index 18a656ab69..0000000000 --- a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- - - name: Set inventory content - copy: - dest: "{{ lookup('env', 'INVENTORY_DIR') }}/tmp.vmware.yml" - content: | - {{ content }} - hostname: '{{ vcenter_hostname }}' - username: '{{ vcenter_username }}' - password: '{{ vcenter_password }}' - port: '{{ vcenter_port|default('443') }}' - validate_certs: {{ vmware_validate_certs|default('no') }} - changed_when: false - check_mode: false - - - meta: refresh_inventory - - - name: Refresh test_host - set_fact: - test_host: "{{ hostvars | dict2items | first}}" - when: hostvars | length > 1 \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory_with_cache.yml b/tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory_with_cache.yml deleted file mode 100644 index f43ae8cf50..0000000000 --- a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory_with_cache.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- hosts: localhost - tasks: - - name: Inventory with 'cache' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - cache: true - properties: [all] \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory_without_cache.yml b/tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory_without_cache.yml deleted file mode 100644 index f07512ccd8..0000000000 --- a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/build_inventory_without_cache.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- hosts: localhost - tasks: - - - name: Inventory with 'cache' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - cache: false - properties: [all] \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/install_dependencies.yml b/tests/integration/targets/inventory_vmware_vm_inventory/playbook/install_dependencies.yml deleted file mode 100644 index d3aab8c60f..0000000000 --- a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/install_dependencies.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: Install dependencies - hosts: localhost - gather_facts: false - tasks: - - pip: - name: toml \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/prepare_vmware.yml b/tests/integration/targets/inventory_vmware_vm_inventory/playbook/prepare_vmware.yml deleted file mode 100644 index 9fc9662f4a..0000000000 --- a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/prepare_vmware.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- name: Prepare VMware folders for testing dynamic inventory folder support - hosts: localhost - gather_facts: false - module_defaults: - group/vmware: - hostname: '{{ vcenter_hostname }}' - username: '{{ vcenter_username }}' - password: '{{ vcenter_password }}' - port: "{{ vcenter_port|default('443') }}" - validate_certs: "{{ vmware_validate_certs|default('no') }}" - tasks: - - import_role: - name: ../prepare_vmware_tests - vars: - setup_attach_host: true - setup_datastore: true - setup_virtualmachines: true \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_inventory_cache.yml b/tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_inventory_cache.yml deleted file mode 100644 index eeed6d266a..0000000000 --- a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_inventory_cache.yml +++ /dev/null @@ -1,51 +0,0 @@ ---- -- name: Test inventory cache - hosts: localhost - gather_facts: false - tasks: - - find: - paths: "{{ lookup('env', 'ANSIBLE_CACHE_PLUGIN_CONNECTION') }}" - patterns: "community.vmware.vmware_vm_inventory*" - register: result - - - name: Cache directory exist - fail: - msg: Cache not found. Please debug. - when: result.matched|int == 0 - ignore_errors: true - - - when: result.matched|int == 0 - meta: end_play - - - set_fact: - cached_groups: "{{groups}}" - cached_hostvars: "{{hostvars}}" - - - meta: refresh_inventory - - - name: 'Compare groups' - fail: - msg: "{{ item.key }} not found in cached groups. Please debug." - when: cached_groups[item.key] is not defined - loop: "{{ q('dict', groups) }}" - loop_control: - label: "{{ item.key }}" - - - name: 'Compare hosts' - fail: - msg: "{{ item.key }} not found in cached hosts. Please debug." - when: cached_hostvars[item.key] is not defined - loop: "{{ q('dict', hostvars) }}" - loop_control: - label: "{{ item.key }}" - - - set_fact: - test_host: "{{ hostvars | dict2items | first }}" - - - name: 'Compare hostvars' - fail: - msg: "{{ item.key }} not found in cached hostvars. Please debug." - when: cached_hostvars[test_host.key][item.key] is not defined - loop: "{{ q('dict', test_host.value) }}" - loop_control: - label: "{{ item.key }}" \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_options.yml b/tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_options.yml deleted file mode 100644 index 3861cc95b8..0000000000 --- a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_options.yml +++ /dev/null @@ -1,332 +0,0 @@ ---- -- name: Test Hostnames option - hosts: localhost - tasks: - - - name: Inventory with 'hostnames' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: false - properties: - - config.name - - runtime.powerState - hostnames: - - 'skip_undefined_empty_none_var' - - 'config.name + "_" + runtime.powerState' - - name: Test properties option are populate - assert: - that: - - "'config.name' in test_host.value" - - "'runtime.powerState' in test_host.value" - - "'name' not in test_host.value" - - name: Test hostnames option - assert: - that: - - test_host.key == (test_host.value['config.name'] + "_" + test_host.value['runtime.powerState']) - - - - name: Inventory with 'all' properties - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: false - properties: ['all'] - - name: Test properties(all) option are populate - assert: - that: - - "'name' in test_host.value" - - "'config.name' in test_host.value" - - - - name: Inventory with 'config' root properties - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: false - properties: - - config - - name: Test properties(config) option are populate - assert: - that: - - "'name' not in test_host.value" - - "'config.name' in test_host.value" - - - - name: Inventory with 'with_path' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_path: true - - name: Test path option - assert: - that: - - "'path' in test_host.value" - - - name: Inventory with rooted 'with_path' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_path: my_center - - name: Test path option with rooted path - assert: - that: - - "'path' in test_host.value" - - "'my_center' in test_host.value.group_names" - - - name: Inventory 'with_nested_properties' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - properties: - - config.name - - config.uuid - with_nested_properties: true - - name: Test 'with_nested_properties' option - assert: - that: - - test_host.value.config.name is defined - - - - name: Inventory 'sanitize_property_name' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - properties: - - config.name - - config.uuid - - runtime.powerState - - with_nested_properties: false - with_sanitized_property_name: true - - name: Test 'with_nested_properties' option - assert: - that: - - test_host.value.runtime_power_state is defined - - - - name: Inventory 'Constructable' options - keyed_groups - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: true - properties: - - config.name - - config.uuid - - config.guestId - - runtime.powerState - keyed_groups: - - key: 'config.guestId' - separator: '' - - key: 'runtime.powerState' - separator: '' - - name: Test 'Constructable' options - keyed_groups - assert: - that: - - "'poweredOff' in test_host.value.group_names" - - - - name: Inventory filters options - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: true - properties: - - config.name - - runtime.powerState - filters: - - runtime.powerState == "poweredOff" - hostnames: - - config.name - - name: Test filters options - assert: - that: - - "'DC0_H0_VM0' in test_host.value.groups.all" - - - - name: Inventory 'Constructable' options - compose, groups - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: true - properties: - - config.uuid - - config.guestId - - runtime.powerState - - config.name - compose: - ansible_host: 'config.name' - composed_var: 'config.name' - groups: - VMs: true - keyed_groups: - - key: 'config.guestId' - separator: '' - - key: 'runtime.powerState' - separator: '' - - name: Test 'Constructable' options - compose, groups - assert: - that: - - "'VMs' in test_host.value.group_names" - - "'poweredOff' in test_host.value.group_names" - - "'ansible_host' in test_host.value" - - "'composed_var' in test_host.value" - - test_host.value.ansible_host == test_host.value.config.name - - test_host.value.composed_var == test_host.value.config.name - - - - name: Inventory 'with_tag' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: true - with_tags: true - properties: - - config.name - - config.uuid - - config.guestId - - runtime.powerState - - name: Test 'with_tags' options - assert: - that: - - "'tags' in test_host.value" - - "'categories' in test_host.value" - - "'tag_category' in test_host.value" - - - - name: Inventory with binary values (https://github.com/ansible/awx/issues/7052) - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: true - properties: - - config.vmxConfigChecksum - - config.name - - summary.runtime.powerState - hostnames: - - config.name - - name: Test filters options - assert: - that: - - "'DC0_H0_VM0' in test_host.value.groups.all" - - test_host.value.config.name is defined - - test_host.value.config.vmxConfigChecksum is defined - - - - name: Inventory 'resources' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: false - hostnames: - - config.name - properties: - - config.name - resources: - - datacenter: - - DC0 - resources: - - compute_resource: - - DC0_C0 - - name: Test 'resources' options - assert: - that: - - "'DC0_C0_RP0_VM0' in hostvars" - - - name: Inventory 'resources' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: false - hostnames: - - config.name - properties: - - config.name - resources: - - datacenter: - - DC0 - resources: - - compute_resource: - - DC0_C0 - - DC0_C0_NOT_EXIST - - name: Test 'resources' options with 'DC0_C0' and 'DC0_C0_NOT_EXIST' - assert: - that: - - "'DC0_C0_RP0_VM0' in hostvars" - - - name: Inventory 'resources' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: false - hostnames: - - config.name - properties: - - config.name - resources: - - datacenter: - - DC0 - resources: - - compute_resource: - - DC0_C0 - - datacenter: - - DC0 - resources: - - compute_resource: - - DC0_C0_NOT_EXIST - - name: Test 'resources' options with 'DC0_C0' and 'DC0_C0_NOT_EXIST' using two 'datacenter' - assert: - that: - - "'DC0_C0_RP0_VM0' in hostvars" - - - name: Inventory 'resources' option - include_tasks: build_inventory.yml - vars: - content: |- - plugin: community.vmware.vmware_vm_inventory - strict: false - with_nested_properties: false - hostnames: - - config.name - properties: - - config.name - resources: - - datacenter: - - DC0 - resources: - - compute_resource: - - DC0_C0_NOT_EXIST - - name: Test 'resources' options with 'DC0_C0_NOT_EXIST' - assert: - that: - - hostvars | length == 0 diff --git a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_vmware_vm_inventory.yml b/tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_vmware_vm_inventory.yml deleted file mode 100644 index d454ca858a..0000000000 --- a/tests/integration/targets/inventory_vmware_vm_inventory/playbook/test_vmware_vm_inventory.yml +++ /dev/null @@ -1,18 +0,0 @@ -# Test code for the vmware guest dynamic plugin module -# Copyright: (c) 2018, Abhijeet Kasurde -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - ---- -- name: Test VMware Guest Dynamic Inventroy Plugin - hosts: localhost - tasks: - - name: Check that there is 'all' group present in inventory - assert: - that: - - "'all' in groups" - - - name: Check if Hostname and other details are populated in hostvars - assert: - that: - - hostvars[item].name is defined - with_items: "{{ groups['all'] }}" \ No newline at end of file diff --git a/tests/integration/targets/inventory_vmware_vm_inventory/runme.sh b/tests/integration/targets/inventory_vmware_vm_inventory/runme.sh deleted file mode 100755 index e9e7a5a9c2..0000000000 --- a/tests/integration/targets/inventory_vmware_vm_inventory/runme.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash -set -eux - -# Envs -export ANSIBLE_PYTHON_INTERPRETER=${ANSIBLE_TEST_PYTHON_INTERPRETER:-$(command -v python)} -export ANSIBLE_INVENTORY_ENABLED="community.vmware.vmware_vm_inventory,host_list,ini" -export ANSIBLE_CACHE_PLUGIN_CONNECTION="${PWD}/inventory_cache" -export ANSIBLE_CACHE_PLUGIN="jsonfile" - -export INVENTORY_DIR="${PWD}/_test/hosts" -mkdir -p "${INVENTORY_DIR}" 2>/dev/null -touch "${INVENTORY_DIR}/empty.vmware.yml" - -cleanup() { - echo "Cleanup" - if [ -d "${ANSIBLE_CACHE_PLUGIN_CONNECTION}" ]; then - echo "Removing ${ANSIBLE_CACHE_PLUGIN_CONNECTION}" - rm -rf "${ANSIBLE_CACHE_PLUGIN_CONNECTION}" - fi - - if [ -d "${INVENTORY_DIR}" ]; then - echo "Removing ${INVENTORY_DIR}" - rm -rf "${INVENTORY_DIR}" - fi - - unset ANSIBLE_INVENTORY_ENABLED - unset ANSIBLE_CACHE_PLUGIN ANSIBLE_CACHE_PLUGIN_CONNECTION - unset INVENTORY_DIR - - echo "Done" -} - -trap cleanup INT TERM EXIT - -# Prepare tests -ansible-playbook playbook/prepare_vmware.yml "$@" - -# Test Cache -# Cache requires jsonfile -ansible-playbook playbook/build_inventory_with_cache.yml "$@" -ansible-inventory -i "${INVENTORY_DIR}" --list 1>/dev/null -ansible-playbook -i "${INVENTORY_DIR}" playbook/test_inventory_cache.yml "$@" - -# Test YAML and TOML -ansible-playbook playbook/install_dependencies.yml "$@" -ansible-playbook playbook/build_inventory_without_cache.yml "$@" -ansible-inventory -i "${INVENTORY_DIR}" --list --yaml 1>/dev/null -if ${ANSIBLE_PYTHON_INTERPRETER} -m pip list 2>/dev/null | grep toml >/dev/null 2>&1; then - ansible-inventory -i "${INVENTORY_DIR}" --list --toml 1>/dev/null -fi - -# # Test playbook with the given inventory -ansible-playbook -i "${INVENTORY_DIR}" playbook/test_vmware_vm_inventory.yml "$@" - -# Test options -ansible-playbook -i "${INVENTORY_DIR}" playbook/test_options.yml "$@" diff --git a/tests/integration/targets/vmware_vm_inventory/aliases b/tests/integration/targets/vmware_vm_inventory/aliases deleted file mode 100644 index 1abfff23db..0000000000 --- a/tests/integration/targets/vmware_vm_inventory/aliases +++ /dev/null @@ -1,2 +0,0 @@ -cloud/vcenter -zuul/vmware/vcenter_1esxi diff --git a/tests/integration/targets/vmware_vm_inventory/ansible.cfg b/tests/integration/targets/vmware_vm_inventory/ansible.cfg deleted file mode 100644 index a0048a90fb..0000000000 --- a/tests/integration/targets/vmware_vm_inventory/ansible.cfg +++ /dev/null @@ -1,9 +0,0 @@ -[defaults] -roles_path = .. - -[inventory] -enable_plugins = community.vmware.vmware_vm_inventory -cache = False -#cache = True -#cache_plugin = jsonfile -#cache_connection = inventory_cache diff --git a/tests/integration/targets/vmware_vm_inventory/prepare_environment.yml b/tests/integration/targets/vmware_vm_inventory/prepare_environment.yml deleted file mode 100644 index 7e24b2d949..0000000000 --- a/tests/integration/targets/vmware_vm_inventory/prepare_environment.yml +++ /dev/null @@ -1,57 +0,0 @@ ---- -- hosts: localhost - module_defaults: - group/vmware: - hostname: '{{ vcenter_hostname }}' - username: '{{ vcenter_username }}' - password: '{{ vcenter_password }}' - port: "{{ vcenter_port|default('443') }}" - validate_certs: "{{ vmware_validate_certs|default('no') }}" - tasks: - - import_role: - name: prepare_vmware_tests - vars: - setup_attach_host: true - setup_datastore: true - - - name: Create VM - vmware_guest: - hostname: "{{ vcenter_hostname }}" - username: "{{ vcenter_username }}" - password: "{{ vcenter_password }}" - datacenter: "{{ dc1 }}" - validate_certs: false - name: test_vm1 - folder: vm - esxi_hostname: "{{ esxi1 }}" - state: powered-on - guest_id: debian8_64Guest - disk: - - size_gb: 1 - type: thin - datastore: local - cdrom: - - controller_number: 0 - unit_number: 0 - type: iso - iso_path: "[{{ ro_datastore }}] fedora.iso" - hardware: - # vmware_guest_disk need vmx-13 to reconfigure the disks - version: 13 - memory_mb: 1024 - num_cpus: 1 - scsi: paravirtual - register: vm_create - - - copy: - dest: vmware.yaml - content: | - plugin: community.vmware.vmware_vm_inventory - strict: false - hostname: {{ vcenter_hostname }} - username: {{ vcenter_username }} - password: "{{ vcenter_password }}" - validate_certs: false - with_tags: true - hostnames: - - config.name diff --git a/tests/integration/targets/vmware_vm_inventory/runme.sh b/tests/integration/targets/vmware_vm_inventory/runme.sh deleted file mode 100755 index 8cecbac348..0000000000 --- a/tests/integration/targets/vmware_vm_inventory/runme.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -# shellcheck disable=SC2086,SC2048 -set -eux -export ANSIBLE_CONFIG=ansible.cfg -ansible-playbook prepare_environment.yml $* -ansible-inventory --list -i vmware.yaml -exec ansible-playbook -i vmware.yaml test_inventory.yml $* diff --git a/tests/integration/targets/vmware_vm_inventory/test_inventory.yml b/tests/integration/targets/vmware_vm_inventory/test_inventory.yml deleted file mode 100644 index 6c1ffb6744..0000000000 --- a/tests/integration/targets/vmware_vm_inventory/test_inventory.yml +++ /dev/null @@ -1,10 +0,0 @@ -# Test code for the vmware guest dynamic plugin module -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - ---- -- hosts: localhost - tasks: - - assert: - that: - - "{{ groups['debian8_64Guest'] | length }} == 1" - - hostvars['test_vm1'] is defined From 2a9bec88c09a00a6aa364b1c195aaa0704825d56 Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Thu, 1 May 2025 12:12:02 +0200 Subject: [PATCH 12/12] Fix deleting content libraries --- .../tasks/teardown_with_esxi.yml | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml index 8c97e7ee9e..61de211662 100644 --- a/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml +++ b/tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -41,7 +41,7 @@ when: - not item.name.startswith("vCLS") -- name: Build a list of libraries +- name: Get a list of libraries community.vmware.vmware_content_library_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' @@ -52,18 +52,27 @@ delay: 3 until: result is not failed -- debug: - var: result +- name: Build a list of libraries + community.vmware.vmware_content_library_info: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + validate_certs: false + library_id: '{{ item }}' + register: content_libs + delay: 3 + with_items: '{{ result.content_libs }}' -- name: Delete library +- name: Delete libraries community.vmware.vmware_content_library_manager: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' validate_certs: false - library_name: "{{ lib_result.library_name }}" + library_name: "{{ item.content_lib_details[0].library_name }}" state: absent - with_items: "{{ result.content_libs }}" + with_items: "{{ content_libs.results }}" + when: content_libs.results is truthy - name: Get a list of all the datacenters community.vmware.vmware_datacenter_info: