Created
May 30, 2023 21:54
-
-
Save tsaavik/fbad15ac31b9d524e1ccbdb18a93e244 to your computer and use it in GitHub Desktop.
AWS CESI Script
This file contains 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/bash | |
# | |
# This script grabs the Name, Ip and environment tags from aws. | |
# It then grabs a cesi conf header file and appends (using heredocs). | |
config="/opt/cesi/defaults/cesi.conf.toml" | |
tmpconf="/tmp/cesi.conf.toml" | |
# Create the header in our new copy of conf file | |
cp -f "${config}.head" ${tmpconf} | |
# fetch name, ip, staging from ec2 and stuff into config using heredoc | |
while read -r ip name environment; do | |
cat << EOF >> ${tmpconf} | |
[[nodes]] | |
name = "${name} - ${ip}" | |
environment = "${environment}" | |
username = "" | |
password = "" | |
host = "${ip}" | |
port = "9001" | |
EOF | |
done < <(aws ec2 describe-instances \ | |
--query 'Reservations[*].Instances[*].{Instance:InstanceId,Instance:PrivateIpAddress,environment:Tags[?Key==`environment`]|[0].Val | |
ue,Name:Tags[?Key==`Name`]|[0].Value}' \ | |
--output text |sort -k 2) | |
#Any changes? Then copy new conf into place and restart cesi | |
if ! diff ${tmpconf} ${config} ;then | |
echo "Changes detected, overwriting cesi conf and signaling config reload" | |
cp ${tmpconf} ${config} | |
pkill -HUP -f cesi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment