Skip to content

Instantly share code, notes, and snippets.

@toritori0318
Created December 8, 2015 16:33
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 toritori0318/0ad3aab875c73f68eaf3 to your computer and use it in GitHub Desktop.
Save toritori0318/0ad3aab875c73f68eaf3 to your computer and use it in GitHub Desktop.
Consulからイベント受け取ってItamae実行とか
#!/bin/sh
if [ ! -p /dev/stdin ] ; then
exit 0
fi
VM=""
RECIPE=""
# 標準入力から受け取り
STDIN_STR=$(cat -)
PAYLOAD=`echo $STDIN_STR | jq -r '.[0] .Payload' | base64 -d`
# key=value の組をパース
for kv in $PAYLOAD; do
set -- `echo $kv | tr '=' ' '`
if [ "$1" == "vm" ] ; then
VM=$2
elif [ "$1" == "recipe" ] ; then
RECIPE=$2
fi
done
# recipe repo clone
git clone http://hogehoge/itame-recipes.git /tmp/itame-recipes
cd /tmp/itame-recipes
# exec itamae
if [ "${RECIPE}" != "" ]; then
/usr/local/bin/bundle exec /usr/local/bin/itamae local --node-json nodes/${VM}.json ${RECIPE}
else
/usr/local/bin/bundle exec /usr/local/bin/itamae local --node-json nodes/${VM}.json entrypoint.rb
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment