Browse Source

Initial file

Should be in /usr/local/sbin - will pull down & apply Ansible configs
master
dave 8 months ago
parent
commit
7aa8bfaee5
  1. 61
      usr.local.sbin/update-and-apply-ansible.sh

61
usr.local.sbin/update-and-apply-ansible.sh

@ -0,0 +1,61 @@
#!/bin/sh
## keeps the ansible playbooks updated from gitea
## a quick check confirms alterationa to local files
## else.. those are updated with latest from gitea
set -u
## -- path to the Ansible dirs
#ANSBASE=/var/lib/ansible/
ANSBASE="/root/ansible"
REPO="ansible-fmb"
BASE="ts-el9.local"
INVENTORY=${ANSBASE}/${REPO}
echo "$(date +'%F_%R:%S'): ==== $(basename $0) START ==== "
## -- create directory if missing
[ ! -d ${ANSBASE} ] && mkdir -p ${ANSBASE}
cd ${ANSBASE}
if [ ! -d ${ANSBASE}/${REPO} ]
then
## -- initial clone here if dir is missing
echo "$(date +'%F_%R:%S'): initial clone needed:"
git clone deploy:/tombstones/${REPO}.git ${ANSBASE}/${REPO}
elif [ -d ${ANSBASE}/${REPO} ]
then
## -- check first
echo -e "$(date +'%F_%R:%S'): checking ${REPO} ... \c"
cd ${ANSBASE}/${REPO}
STATUS="$(git status | tail -n1)"
## -- Checking if something changed locally that needs to be fixed
if [[ ! ${STATUS} =~ "nothing to commit" ]]
then
## -- oops... something has changed our end - fix it!
echo "fix required - showing diff on next line:"
git diff
git fetch origin &> /dev/null
git reset --hard origin/master &> /dev/null
echo "$(date +'%F_%R:%S'): ${REPO} fixed!"
else
echo " ${STATUS}"
fi
## -- perform an update (pull) here
RESULTS="$(git pull | tail -n1)"
echo "$(date +'%F_%R:%S'): ${RESULTS}"
if [[ ! ${RESULTS} =~ "up to date" ]]
then
## -- looks like there's been some changes
echo -e "$(date +'%F_%R:%S'): applying yaml from ${REPO} ..."
ansible-playbook -D -i ${ANSBASE}/${REPO}/inventory -l ${BASE} ${ANSBASE}/${REPO}/standalone-playbooks/epel.yml
ansible-playbook -D -i ${ANSBASE}/${REPO}/inventory -l ${BASE} ${ANSBASE}/${REPO}/site.yml
fi
fi
echo "$(date +'%F_%R:%S'): ------ $(basename $0) END ------"
Loading…
Cancel
Save