Skip to content

Instantly share code, notes, and snippets.

@nmarley
Created August 7, 2017 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmarley/9a96be85252e4f56057069733b2449dd to your computer and use it in GitHub Desktop.
Save nmarley/9a96be85252e4f56057069733b2449dd to your computer and use it in GitHub Desktop.
DigitalOcean tag splitter
#! /bin/bash
# TAGLIST=$(curl -s 169.254.169.254/metadata/v1/tags/)
TAGLIST="ansible-role:02-openvpn ansible-role:01-common app:OpenVPN name:testtagger01"
ROLE_TAGS=()
for T in $TAGLIST; do
IFS=:
read -r Key Value <<< "$T"
if [ "ansible-role" = "${Key}" ]; then
ROLE_TAGS+=($Value)
# echo $Value
fi
# echo "Key=${Key},Value=${Value}"
unset IFS
done
echo "Role Tags = [${ROLE_TAGS[@]}]"
SORTED=$(echo ${ROLE_TAGS[@]} | tr " " "\n" | sort -n)
for ANSIBLE_ROLE in $SORTED; do
echo $ANSIBLE_ROLE
# run ansible playbooks/roles here...
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment