Last active
February 16, 2017 06:09
-
-
Save adamjkeller/5377fbcee0379372639474226c091697 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env bash | |
| set -eux | |
| DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
| zone=${1} | |
| stack_name=${2} | |
| securitygroup=${3:-null} | |
| service_name=${4} | |
| iplist=() | |
| checksecuritygroup() { | |
| aws ec2 describe-security-groups --group-ids ${securitygroup} &>/dev/null && delete=false || delete=true | |
| } | |
| getjson() { | |
| json=$(aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" "Name=tag:Name,Values=${stack_name}-kafka" --output json) | |
| } | |
| getiplist() { | |
| #iplist=($(echo ${json} | jq -r '.[][].Instances[].PrivateIpAddress')) | |
| iplist=($(echo ${json}|jq -r --arg stack "${stack_name}-kafka" '.Reservations[].Instances[].NetworkInterfaces[]|select(.Description==$stack)|.PrivateIpAddress')) | |
| } | |
| formatiplist() { | |
| formattediplist=$(echo ${iplist[@]} | tr ' ' ',') | |
| } | |
| route53set() { | |
| ansible localhost -i /dev/null -m route53 -a " | |
| command=create | |
| zone=${zone} | |
| record=${service_name}-${stack_name}.${zone} | |
| type=A | |
| value=${formattediplist} | |
| overwrite=yes | |
| wait=yes" | |
| } | |
| getvalue() { | |
| value=$(ansible localhost -i /dev/null -m route53 -a " | |
| command=get | |
| zone=${zone} | |
| record=${service_name}-${stack_name}.${zone} | |
| type=A" | grep '"value": ' | awk '{print $2}' | grep -o '".*"' | tr -d '"') | |
| } | |
| route53delete() { | |
| ansible localhost -i /dev/null -m route53 -a " | |
| command=delete | |
| zone=${zone} | |
| record=${service_name}-${stack_name}.${zone} | |
| type=A | |
| value=${value} | |
| overwrite=yes" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment