55 lines
2.5 KiB
Bash
Executable file
55 lines
2.5 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
if [ $# -ge 1 ]; then
|
|
BRANCH="$(git branch --show-current || git rev-parse --abbrev-ref HEAD)"
|
|
MACHINE="$1"
|
|
shift 1
|
|
else
|
|
printf "%s\n" "USAGE: $0 machine_fqdn [ansible-playbook_options]"
|
|
exit 1;
|
|
fi;
|
|
|
|
BIN_ANSIBLE='/usr/bin/ansible-playbook'
|
|
|
|
ADMIN_USER='ansible'
|
|
ANSIBLE_SERVER="ov2.rhizogen.es.eu.org"
|
|
SSH_PORT="57473"
|
|
|
|
SMACHINE="${MACHINE%.rhizogen.es.eu.org}"
|
|
DIRGIT="git"
|
|
|
|
configs_dir="${CONFIGS_DIR:-${HOME}/git/configs}"
|
|
remote_configs_dir="/tmp/${DIRGIT}/configs-${BRANCH}-${SMACHINE}"
|
|
PASSWORD_STORE_DIR="${HOME}/git/pass-ansible"
|
|
remote_password_store_dir="/tmp/${DIRGIT}/pass-ansible-${BRANCH}"
|
|
echo "PASSWORD_STORE_DIR: $PASSWORD_STORE_DIR"
|
|
echo "remote_password_store_dir: $remote_password_store_dir"
|
|
|
|
# copy the working tree
|
|
printf "%s\n" "[SYNC-PASS]"
|
|
printf "%s\n" "* ssh -p ${SSH_PORT} ${ADMIN_USER}@${ANSIBLE_SERVER} mkdir -p ${remote_password_store_dir}"
|
|
ssh -p ${SSH_PORT} "${ADMIN_USER}"@"${ANSIBLE_SERVER}" "mkdir -p ${remote_password_store_dir}"
|
|
printf "%s\n" "* rsync -va -e \"ssh -p ${SSH_PORT}\" --exclude=${PASSWORD_STORE_DIR}/.git --delete ${PASSWORD_STORE_DIR} ${ADMIN_USER}@${ANSIBLE_SERVER}:${remote_password_store_dir}"
|
|
rsync -va -e "ssh -p ${SSH_PORT}" --exclude="${PASSWORD_STORE_DIR}/.git" --delete "${PASSWORD_STORE_DIR}/" "${ADMIN_USER}"@"${ANSIBLE_SERVER}":"${remote_password_store_dir}"
|
|
ret=$?
|
|
if [ $ret -ne 0 ]; then
|
|
printf "%s\n" "Rsync copy failed. Aborting." 1>&2
|
|
exit $ret;
|
|
fi
|
|
printf "%s\n" "[SYNC-CONFIGS]"
|
|
printf "%s\n" "* ssh -p ${SSH_PORT} ${ADMIN_USER}@${ANSIBLE_SERVER} mkdir -p ${remote_configs_dir}"
|
|
ssh -p ${SSH_PORT} "${ADMIN_USER}"@"${ANSIBLE_SERVER}" "mkdir -p ${remote_configs_dir}"
|
|
printf "%s\n" "* rsync -va -e \"ssh -p ${SSH_PORT}\" --exclude-from=${configs_dir}/.gitignore --exclude=${configs_dir}/.git --delete ${configs_dir} ${ADMIN_USER}@${ANSIBLE_SERVER}:${remote_configs_dir}"
|
|
rsync -va -e "ssh -p ${SSH_PORT}" --exclude-from="${configs_dir}/.gitignore" --exclude="${configs_dir}/.git" --delete "${configs_dir}/" "${ADMIN_USER}"@"${ANSIBLE_SERVER}":"${remote_configs_dir}"
|
|
ret=$?
|
|
if [ $ret -ne 0 ]; then
|
|
printf "%s\n" "Rsync copy failed. Aborting." 1>&2
|
|
exit $ret;
|
|
fi
|
|
|
|
# run the playbook via lib/test.sh
|
|
printf "%s\n" "[RUN]"
|
|
printf "%s\n" "* ssh -t -A -p ${SSH_PORT} ${ADMIN_USER}@${ANSIBLE_SERVER} ${remote_configs_dir}/lib/test.sh $BRANCH $MACHINE $@"
|
|
ssh -t -A -p ${SSH_PORT} "${ADMIN_USER}"@"${ANSIBLE_SERVER}" "${remote_configs_dir}"/lib/test.sh $BRANCH $MACHINE $@
|
|
|
|
printf "%s\n" "$0 done."
|