Dynamically exclude roles based on host type
This commit is contained in:
parent
99942dadfb
commit
f4249ea484
|
@ -1,27 +1,51 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
HOSTS="$1"
|
HOSTS="$1"
|
||||||
|
ROLE_LIST=( "virt-common" "docker" "apps" "postgresql" "proxy" )
|
||||||
|
|
||||||
case $HOSTS in
|
# Dynamically remove roles that are incompatible with a host
|
||||||
*:*)
|
OLDIFS="$IFS"
|
||||||
ROLES="['virt-common']" ;;
|
IFS=:
|
||||||
*app*)
|
for target in $HOSTS; do
|
||||||
ROLES="['virt-common', 'docker', 'apps']" ;;
|
case $target in
|
||||||
*db*)
|
*app*)
|
||||||
ROLES="['virt-common', 'postgresql']" ;;
|
ROLE_LIST=( "${ROLE_LIST[@]/postgresql}" )
|
||||||
*prx*|proxy*)
|
ROLE_LIST=( "${ROLE_LIST[@]/proxy}" )
|
||||||
ROLES="['virt-common', 'docker', 'proxy']" ;;
|
;;
|
||||||
*)
|
*db*)
|
||||||
ROLES="['virt-common']" ;;
|
ROLE_LIST=( "${ROLE_LIST[@]/docker}" )
|
||||||
esac
|
ROLE_LIST=( "${ROLE_LIST[@]/apps}" )
|
||||||
|
ROLE_LIST=( "${ROLE_LIST[@]/proxy}" )
|
||||||
|
;;
|
||||||
|
*mda*|media*)
|
||||||
|
ROLE_LIST=( "${ROLE_LIST[@]/apps}" )
|
||||||
|
ROLE_LIST=( "${ROLE_LIST[@]/postgresql}" )
|
||||||
|
ROLE_LIST=( "${ROLE_LIST[@]/proxy}" )
|
||||||
|
;;
|
||||||
|
*prx*|proxy*)
|
||||||
|
ROLE_LIST=( "${ROLE_LIST[@]/apps}" )
|
||||||
|
ROLE_LIST=( "${ROLE_LIST[@]/postgresql}" )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
ROLE_LIST=( "virt-common" ) ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
IFS="$OLDIFS"
|
||||||
|
|
||||||
|
# Transform role list into JSON array
|
||||||
|
ROLES="$(jq -c -M -n '$ARGS.positional | map(select(length > 0))' --args -- "${ROLE_LIST[@]}")"
|
||||||
|
echo "Running roles $ROLES against $HOSTS"
|
||||||
|
|
||||||
|
# Export vars for envsubst
|
||||||
export HOSTS
|
export HOSTS
|
||||||
export ROLES
|
export ROLES
|
||||||
|
|
||||||
|
# Execution of temporary envsubst'ed playbook
|
||||||
PLAYBOOK="playbook-$(tr -dc A-Za-z < /dev/urandom | head -c 10).yml"
|
PLAYBOOK="playbook-$(tr -dc A-Za-z < /dev/urandom | head -c 10).yml"
|
||||||
envsubst < site.yml > "$PLAYBOOK"
|
envsubst < site.yml > "$PLAYBOOK"
|
||||||
ansible-playbook "$PLAYBOOK"
|
ansible-playbook "$PLAYBOOK"
|
||||||
STATUS=$?
|
STATUS=$?
|
||||||
|
|
||||||
|
# Clean up temporary playbook
|
||||||
rm -f "$PLAYBOOK"
|
rm -f "$PLAYBOOK"
|
||||||
exit $STATUS
|
exit $STATUS
|
||||||
|
|
Loading…
Reference in a new issue