kolla-ansible/tools/kolla-ansible
Jeffrey Zhang dd6df534cf make the kolla-ansible python3 compatible
* remove unused sys
* user print() for python3 compatible

TrivalFix

Change-Id: I65c66d0373cdec19da668c3d911f061ce95d1374
2016-01-06 15:31:00 +08:00

97 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
#
# This script can be used to interact with kolla via ansible.
function find_base_dir {
local real_path=$(python -c "import os;print(os.path.realpath('$0'))")
local dir_name="$(dirname "$real_path")"
if [[ ${dir_name} == "/usr/bin" ]]; then
BASEDIR=/usr/share/kolla
elif [[ ${dir_name} == "/usr/local/bin" ]]; then
BASEDIR=/usr/local/share/kolla
else
BASEDIR="${dir_name}/.."
fi
}
function process_cmd {
echo "$ACTION : $CMD"
$CMD
if [[ $? -ne 0 ]]; then
echo "Command failed $CMD"
exit 1
fi
}
function usage {
cat <<EOF
Usage: $0 COMMAND [options]
Options:
--inventory, -i <inventory_path> Specify path to ansible inventory file
--playbook, -p <playbook_path> Specify path to ansible playbook file
--help, -h Show this usage information
Commands:
deploy Deploy and start all kolla containers
pull Pull all images for containers (only pulls, no runnnig container changes)
EOF
}
ARGS=$(getopt -o hi:p: -l help,inventory:,playbook: --name "$0" -- "$@") || { usage >&2; exit 2; }
eval set -- "$ARGS"
find_base_dir
INVENTORY="${BASEDIR}/ansible/inventory/all-in-one"
PLAYBOOK="${BASEDIR}/ansible/site.yml"
while [ "$#" -gt 0 ]; do
case "$1" in
(--inventory|-i)
INVENTORY="$2"
shift 2
;;
(--playbook|-p)
PLAYBOOK="$2"
shift 2
;;
(--help|-h)
usage
shift
exit 0
;;
(--)
shift
break
;;
(*)
echo "error"
exit 3
;;
esac
done
case "$1" in
(deploy)
ACTION="Deploying Playbooks"
CMD="ansible-playbook -i $INVENTORY -e @/etc/kolla/globals.yml -e @/etc/kolla/passwords.yml $PLAYBOOK -e action=deploy"
;;
(pull)
ACTION="Pulling Docker images"
CMD="ansible-playbook -i $INVENTORY -e @/etc/kolla/globals.yml -e @/etc/kolla/passwords.yml $PLAYBOOK -e action=pull"
;;
(*) usage
exit 0
;;
esac
process_cmd