Skip to content

Instantly share code, notes, and snippets.

@takehaya
Created October 24, 2019 18:45
Show Gist options
  • Save takehaya/2c7756531269bdc0a23de95855be5c4a to your computer and use it in GitHub Desktop.
Save takehaya/2c7756531269bdc0a23de95855be5c4a to your computer and use it in GitHub Desktop.
ansibleで使おうとしたやつ供養
#!/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