ansible/test/integration/targets/vmware_inventory/runme.sh
Gonéri Le Bouder 5ecbe9cbbb vcenter provider: Only rely on VMWARE_TEST_PLATFORM
Until now, the vcenter provider was switching between `static` and
`govcsim` depending on the presence of the following configuration file:
`test/integration/cloud-config-vcenter.ini`.

This was not consistent with Worldstream, which we enable with the
`VMWARE_TEST_PLATFORM` environment variable.

We now only rely on `VMWARE_TEST_PLATFORM` to know which platform should be
used. `govcsim` is still the default, this to preserve the original
behaviour.

This commit also rename the following variables to be consistent with the rest
of the code base. It also ensures they are alway defined, even with `govcsim`:

- `VCENTER_HOSTNAME`
- `VCENTER_USERNAME`
- `VCENTER_PASSWORD`
2019-09-20 10:33:44 -04:00

58 lines
1.5 KiB
Bash
Executable file

#!/usr/bin/env bash
[[ -n "$DEBUG" || -n "$ANSIBLE_DEBUG" ]] && set -x
set -euo pipefail
contrib_dir=../../../../contrib/inventory
echo "DEBUG: using ${contrib_dir}"
export ANSIBLE_CONFIG=ansible.cfg
export VMWARE_SERVER="${VCENTER_HOSTNAME}"
export VMWARE_USERNAME="${VCENTER_USERNAME}"
export VMWARE_PASSWORD="${VCENTER_PASSWORD}"
VMWARE_CONFIG=${contrib_dir}/vmware_inventory.ini
trap cleanup INT TERM EXIT
# Remove default inventory config file
if [ -f "${VMWARE_CONFIG}" ];
then
echo "DEBUG: Creating backup of ${VMWARE_CONFIG}"
cp "${VMWARE_CONFIG}" "${VMWARE_CONFIG}.bk"
fi
cat > "${VMWARE_CONFIG}" <<VMWARE_INI
[vmware]
server=${VMWARE_SERVER}
username=${VMWARE_USERNAME}
password=${VMWARE_PASSWORD}
validate_certs=False
VMWARE_INI
function cleanup {
# Revert back to previous one
if [ -f "${VMWARE_CONFIG}.bk" ]; then
echo "DEBUG: Cleanup ${VMWARE_CONFIG}"
mv "${VMWARE_CONFIG}.bk" "${VMWARE_CONFIG}"
fi
}
echo "DEBUG: Using ${VCENTER_HOSTNAME} with username ${VCENTER_USERNAME} and password ${VCENTER_PASSWORD}"
echo "Kill all previous instances"
curl "http://${VCENTER_HOSTNAME}:5000/killall" > /dev/null 2>&1
echo "Start new VCSIM server"
curl "http://${VCENTER_HOSTNAME}:5000/spawn?datacenter=1&cluster=1&folder=0" > /dev/null 2>&1
echo "Debugging new instances"
curl "http://${VCENTER_HOSTNAME}:5000/govc_find"
# Get inventory
ansible-playbook -i ./vmware_inventory.sh "./test_vmware_inventory.yml" --connection=local "$@"
echo "DEBUG: Done"