Created
October 24, 2019 18:45
-
-
Save takehaya/2c7756531269bdc0a23de95855be5c4a to your computer and use it in GitHub Desktop.
ansibleで使おうとしたやつ供養
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -eu | |
dir="" | |
if [ $# -ne 1 ]; then | |
dir=`terraform workspace show` | |
fi | |
if [ -e ./terraform.tfstate.d/${dir}/terraform.tfstate ]; then | |
rm -f hosts | |
if [ "`uname`" == "Darwin" ]; then | |
ip=`cat ./terraform.tfstate.d/${dir}/terraform.tfstate |jq '.outputs.k8s_lb_server_ipaddress.value as $lb|[.outputs[].value[]] as $all|({cloud_servers:{hosts:$all}}+(select($lb[0] != null)|{lb_server:{host:$lb}}))//{cloud_servers:{hosts:$all}}'` | |
else | |
ip=`cat ./terraform.tfstate.d/${dir}/terraform.tfstate |jq '.outputs.k8s_lb_server_ipaddress.value as $lb|[.outputs[].value[]] as $all|({cloud_servers:{hosts:$all}}+(select($lb[0] != null)|{lb_server:{host:$lb}}))//{cloud_servers:{hosts:$all}}'` | |
fi | |
cat << EOS > hosts | |
$ip | |
EOS | |
chmod +x hosts | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment