54 lines
1.7 KiB
Bash
Executable file
54 lines
1.7 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
if [ $# -ge 1 ]; then
|
|
MACHINE="$1"
|
|
shift 1
|
|
else
|
|
printf "%s\n" "USAGE: $0 machine_fqdn [ansible-playbook_options]"
|
|
exit 1;
|
|
fi;
|
|
|
|
ADMIN_USER='ansible'
|
|
ANSIBLE_SERVER="ov2.rhizogen.es.eu.org"
|
|
SSH_PORT="57473"
|
|
|
|
configs_dir="${CONFIGS_DIR:-${HOME}/git/configs}"
|
|
DIRGIT="git"
|
|
#BIN_GIT="git"
|
|
BIN_GIT="./gitwrap.sh"
|
|
|
|
remote_configs_dir='~/git/configs'
|
|
|
|
# Check syntax locally before pushing
|
|
printf "%s\n" "[SYNTAX CHECK]"
|
|
printf "%s\n" "* ansible-playbook -i ${configs_dir}/inventory/hosts --syntax-check ${configs_dir}/${MACHINE}.yaml"
|
|
ansible-playbook -i "${configs_dir}/inventory/hosts" --syntax-check "${configs_dir}/${MACHINE}.yaml"
|
|
ret=$?
|
|
if [ $ret -ne 0 ]; then
|
|
printf "%s\n" "ERROR: Syntax check failed. Changes won't be pushed. Aborting." >&2
|
|
exit 2
|
|
fi
|
|
|
|
case $0 in
|
|
*/push-prod.sh)
|
|
# Push and run remote prod command
|
|
printf "%s\n" "[PUSH-PROD]"
|
|
printf "%s\n" "* ${BIN_GIT} push && ssh -t -A -p ${SSH_PORT} ${ADMIN_USER}@${ANSIBLE_SERVER} ${remote_configs_dir}/lib/pull-prod.sh $MACHINE $@"
|
|
${BIN_GIT} push && \
|
|
ssh -t -A -p ${SSH_PORT} "${ADMIN_USER}"@"${ANSIBLE_SERVER}" "${remote_configs_dir}/lib/pull-prod.sh $MACHINE $@"
|
|
;;
|
|
*/push-test.sh)
|
|
# Push and run remote test command
|
|
BRANCH="$(git branch --show-current || git rev-parse --abbrev-ref HEAD)"
|
|
printf "%s\n" "[PUSH-TEST]"
|
|
printf "%s\n" "* ${BIN_GIT} push && ssh -t -A -p ${SSH_PORT} ${ADMIN_USER}@${ANSIBLE_SERVER} ${remote_configs_dir}/lib/pull-test.sh $BRANCH $MACHINE $@"
|
|
${BIN_GIT} push && \
|
|
ssh -t -A -p ${SSH_PORT} "${ADMIN_USER}"@"${ANSIBLE_SERVER}" "${remote_configs_dir}/lib/pull-test.sh $BRANCH $MACHINE $@"
|
|
;;
|
|
*)
|
|
printf "%s\n" "Script has been called with unknown name $0" >&2
|
|
printf "%s\n" "Exiting." >&2
|
|
exit 2;
|
|
esac
|
|
|
|
printf "%s\n" "$0 done."
|