From 04e7dfa484f83db93d612ae018877b6b19e4bada Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Wed, 25 Dec 2024 19:44:38 +0100 Subject: [PATCH] Deprecate vmware_host_inventory --- .github/workflows/extra-docs-linting.yml | 2 +- .../2279-deprecate-vmware_host_inventory.yml | 3 + meta/runtime.yml | 5 + plugins/inventory/vmware_host_inventory.py | 4 + .../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 ----- 14 files changed, 13 insertions(+), 415 deletions(-) create mode 100644 changelogs/fragments/2279-deprecate-vmware_host_inventory.yml 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 diff --git a/.github/workflows/extra-docs-linting.yml b/.github/workflows/extra-docs-linting.yml index 782fd9c928..87d8563cff 100644 --- a/.github/workflows/extra-docs-linting.yml +++ b/.github/workflows/extra-docs-linting.yml @@ -34,7 +34,7 @@ jobs: - name: Install dependent collections run: > ansible-galaxy collection install - 'vmware.vmware>=1.7.1' + 'vmware.vmware>=1.8.0' - name: Run collection docs linter run: antsibull-docs lint-collection-docs . --plugin-docs --skip-rstcheck diff --git a/changelogs/fragments/2279-deprecate-vmware_host_inventory.yml b/changelogs/fragments/2279-deprecate-vmware_host_inventory.yml new file mode 100644 index 0000000000..2be810ba21 --- /dev/null +++ b/changelogs/fragments/2279-deprecate-vmware_host_inventory.yml @@ -0,0 +1,3 @@ +deprecated_features: + - vmware_host_inventory - the inventory plugin is deprecated and will be removed in community.vmware 7.0.0 + (https://github.com/ansible-collections/community.vmware/pull/2279). diff --git a/meta/runtime.yml b/meta/runtime.yml index 6a46b594b9..0670ba2cf4 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -180,6 +180,11 @@ action_groups: - vsphere_file plugin_routing: + inventory: + vmware_host_inventory: + deprecation: + removal_version: 7.0.0 + warning_text: Use vmware.vmware.esxi_hosts instead. modules: vmware_cluster: deprecation: diff --git a/plugins/inventory/vmware_host_inventory.py b/plugins/inventory/vmware_host_inventory.py index eaac4f7dac..a707737e72 100644 --- a/plugins/inventory/vmware_host_inventory.py +++ b/plugins/inventory/vmware_host_inventory.py @@ -10,6 +10,10 @@ DOCUMENTATION = r""" name: vmware_host_inventory + deprecated: + removed_in: 7.0.0 + why: This module has been moved to the L(new vmware.vmware collection,https://forum.ansible.com/t/5880) + alternative: Use M(vmware.vmware.esxi_hosts) instead. short_description: VMware ESXi hostsystem inventory source author: - Abhijeet Kasurde (@Akasurde) 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 "$@"