diff --git a/playbook-template/bootstrap.sh b/playbook-template/bootstrap.sh new file mode 100644 index 0000000000000000000000000000000000000000..1b2f79040ec70f7dead43e7b465e8b695429dad3 --- /dev/null +++ b/playbook-template/bootstrap.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +reporaw="https://git.sch.bme.hu/kszk/sysadmin/ansible/ansci/-/raw/master/playbook-template" + +download() { + local url="$1" + local dest="$2" + if command -v wget &>/dev/null + then + wget "$url" -O "$dest" + else + curl "$url" -O "$dest" + fi +} + +downloadFile() { + download "$reporaw/$1" "$1" +} + + +update() { + # TODO: versioning with tags + + if $NOUPDATE + then + return 0 + fi + + local prevhash + prevhash="$(md5hash "$0")" + download "$reporaw/bootstrap.sh" "$0" + local newhash + newhash="$(md5hash "$0")" + + if [[ "$prevhash" != "$newhash" ]] + then + exec bash "$0" + fi +} + +update + +downloadFile "requirements.python.txt" +downloadFile "requirements.galaxy.yml" + +if ! command -v virtualenv &>/dev/null +then + echo "This command needs virtualenv to run." + echo "Install it like this:" + printf "\tpip3 install --user virtualenv\n" + printf "\texport PATH=\"~/.local/bin:\$PATH\"\n" + exit 1 +fi + +if [[ ! -d .venv ]] +then + virtualenv .venv +fi + +source .venv/bin/activate +pip install -r requirements.python.txt +ansible-galaxy install -r requirements.galaxy.yml +ansible-playbook -i inventory.yaml playbook.yml