|
|
@ -0,0 +1,63 @@ |
|
|
|
#!/bin/bash |
|
|
|
SERVER=$1 |
|
|
|
PLAYBOOK=$2 |
|
|
|
SITE_NAME=$3 |
|
|
|
DOMAIN_NAME=$4 |
|
|
|
|
|
|
|
while [[ "$#" -gt 0 ]]; do |
|
|
|
case $1 in |
|
|
|
-f|--force) force=1; shift ;; |
|
|
|
esac |
|
|
|
shift |
|
|
|
done |
|
|
|
|
|
|
|
usage() { |
|
|
|
echo "Usage: run-vps-playbook.sh server playbook site_name domain_name" |
|
|
|
echo "server - domain or ip address of the vps server" |
|
|
|
echo "playbook - playbook file" |
|
|
|
echo "site_name - site name, e.g. intermetiz - that is a project name used for create home directory and www directory, and database dump base file name" |
|
|
|
echo "domain_name - domain name, e.g. intermetiz.ru" |
|
|
|
} |
|
|
|
|
|
|
|
if [[ -z "$SERVER" ]]; then |
|
|
|
echo "You must defined SERVER as first argument" |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
if [[ -z "$PLAYBOOK" ]]; then |
|
|
|
echo "You must defined PLAYBOOK as second argument" |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
if [[ -z "$SITE_NAME" ]]; then |
|
|
|
echo "You must defined SITE_NAME as third argument" |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
if [[ -z "$DOMAIN_NAME" ]]; then |
|
|
|
echo "You must defined DOMAIN_NAME as fourth argument" |
|
|
|
usage |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
COMMAND=$(cat <<EOF |
|
|
|
ansible-playbook -e "lxc_host=${SERVER}" -e "initial_site_name=${SITE_NAME}" -e "domain_name=${DOMAIN_NAME}" -e runner=site |
|
|
|
EOF |
|
|
|
) |
|
|
|
|
|
|
|
COMMAND="${COMMAND} ${PLAYBOOK}" |
|
|
|
|
|
|
|
if [[ -z "$force" ]]; then |
|
|
|
printf 'Launch ansible playbook:\n%s\n' "${COMMAND}" |
|
|
|
read -p "Are you sure? " -n 1 -r |
|
|
|
echo # (optional) move to a new line |
|
|
|
if [[ $REPLY =~ ^[Yy]$ ]] |
|
|
|
then |
|
|
|
/bin/bash -c "${COMMAND}" |
|
|
|
fi |
|
|
|
else |
|
|
|
/bin/bash -c "${COMMAND}" |
|
|
|
fi |