Skip to content

Instantly share code, notes, and snippets.

@mmastoras
Created March 3, 2020 17:53
Show Gist options
  • Save mmastoras/a1ceb7f81138a5e235cd5cd988aef54e to your computer and use it in GitHub Desktop.
Save mmastoras/a1ceb7f81138a5e235cd5cd988aef54e to your computer and use it in GitHub Desktop.
#!/bin/bash
wget -O ~/.ssh/devops_id_rsa ${DEVOPS_SSH_PRIVATE_KEY} > /dev/null 2>&1 && chmod 0600 ~/.ssh/devops_id_rsa
# get bastion IPs
scratch_ip=$(aws ec2 describe-instances --region "us-west-2" --filters "Name=tag:Name,Values=reputedly-scratch" --query 'Reservations[*].Instances[*].[PrivateIpAddress]' --output text)
orange_ip_list=$(aws ec2 describe-instances --region "us-west-2" --filters "Name=tag:Type,Values=orange" --query 'Reservations[*].Instances[*].[PrivateIpAddress]' --output text)
SAVEIFS=$IFS # Save current IFS
IFS=$'\n' # Change IFS to new line
orange_ips=($orange_ip_list) # split to array $names
IFS=$SAVEIFS # Restore IFS
printf "Converge scratch...\n"
ssh -t devops@${scratch_ip} "sudo chef-client"
printf "Converge orange workers...\n"
for i in "${orange_ips[@]}"
do
ssh -t devops@${i} "sudo chef-client"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment