2018-09-22 08:38:20 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
[[ -n "$DEBUG" || -n "$ANSIBLE_DEBUG" ]] && set -x
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2019-01-17 07:34:09 +01:00
|
|
|
contrib_dir=../../../../contrib/inventory
|
2018-09-22 08:38:20 +02:00
|
|
|
|
|
|
|
echo "DEBUG: using ${contrib_dir}"
|
|
|
|
|
|
|
|
export ANSIBLE_CONFIG=ansible.cfg
|
2019-08-29 19:54:39 +02:00
|
|
|
export VMWARE_SERVER="${VCENTER_HOSTNAME}"
|
|
|
|
export VMWARE_USERNAME="${VCENTER_USERNAME}"
|
|
|
|
export VMWARE_PASSWORD="${VCENTER_PASSWORD}"
|
2018-09-22 08:38:20 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-08-29 19:54:39 +02:00
|
|
|
echo "DEBUG: Using ${VCENTER_HOSTNAME} with username ${VCENTER_USERNAME} and password ${VCENTER_PASSWORD}"
|
2018-09-22 08:38:20 +02:00
|
|
|
|
|
|
|
echo "Kill all previous instances"
|
2019-08-29 19:54:39 +02:00
|
|
|
curl "http://${VCENTER_HOSTNAME}:5000/killall" > /dev/null 2>&1
|
2018-09-22 08:38:20 +02:00
|
|
|
|
|
|
|
echo "Start new VCSIM server"
|
2019-08-29 19:54:39 +02:00
|
|
|
curl "http://${VCENTER_HOSTNAME}:5000/spawn?datacenter=1&cluster=1&folder=0" > /dev/null 2>&1
|
2018-09-22 08:38:20 +02:00
|
|
|
|
|
|
|
echo "Debugging new instances"
|
2019-08-29 19:54:39 +02:00
|
|
|
curl "http://${VCENTER_HOSTNAME}:5000/govc_find"
|
2018-09-22 08:38:20 +02:00
|
|
|
|
|
|
|
# Get inventory
|
2019-01-17 07:34:09 +01:00
|
|
|
ansible-playbook -i ./vmware_inventory.sh "./test_vmware_inventory.yml" --connection=local "$@"
|
2018-09-22 08:38:20 +02:00
|
|
|
|
|
|
|
echo "DEBUG: Done"
|