VMware: Refactor guest inventory plugin (#52642)

* VMware: Refactor guest inventory plugin
* Review comments

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde
2019-02-22 09:55:57 +05:30
committed by GitHub
parent 17bfc60423
commit e41b98ffb5
4 changed files with 264 additions and 191 deletions

View File

@@ -3,3 +3,6 @@ inventory = test-config.vmware.yaml
[inventory]
enable_plugins = vmware_vm_inventory
cache = True
cache_plugin = jsonfile
cache_connection = inventory_cache

View File

@@ -4,6 +4,9 @@
set -euo pipefail
# Required to differentiate between Python 2 and 3 environ
PYTHON=${ANSIBLE_TEST_PYTHON_INTERPRETER:-python}
export ANSIBLE_CONFIG=ansible.cfg
export vcenter_host="${vcenter_host:-0.0.0.0}"
export VMWARE_SERVER="${vcenter_host}"
@@ -18,7 +21,20 @@ validate_certs: False
with_tags: False
VMWARE_YAML
trap 'rm -f "${VMWARE_CONFIG}"' INT TERM EXIT
cleanup() {
echo "Cleanup"
if [ -f "${VMWARE_CONFIG}" ]; then
rm -f "${VMWARE_CONFIG}"
fi
if [ -d "$(pwd)/inventory_cache" ]; then
echo "Removing $(pwd)/inventory_cache"
rm -rf "$(pwd)/inventory_cache"
fi
echo "Done"
exit 0
}
trap cleanup INT TERM EXIT
echo "DEBUG: Using ${vcenter_host} with username ${VMWARE_USERNAME} and password ${VMWARE_PASSWORD}"
@@ -33,5 +49,23 @@ curl "http://${vcenter_host}:5000/govc_find"
# Get inventory
ansible-inventory -i ${VMWARE_CONFIG} --list
# Get inventory using YAML
ansible-inventory -i ${VMWARE_CONFIG} --list --yaml
# Install TOML for --toml
${PYTHON} -m pip install toml
# Get inventory using TOML
ansible-inventory -i ${VMWARE_CONFIG} --list --toml
echo "Check if cache is working for inventory plugin"
ls "$(pwd)/inventory_cache/vmware_vm_*" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Cache directory not found. Please debug"
exit 1
fi
echo "Cache is working"
# Test playbook with given inventory
ansible-playbook -i ${VMWARE_CONFIG} test_vmware_vm_inventory.yml --connection=local "$@"