Skip to content

Instantly share code, notes, and snippets.

@jonathanhle
Created April 29, 2016 21:22
Show Gist options
  • Save jonathanhle/d1ebbb816c3b261c7d3aaad929b3b4bc to your computer and use it in GitHub Desktop.
Save jonathanhle/d1ebbb816c3b261c7d3aaad929b3b4bc to your computer and use it in GitHub Desktop.
Use ansible to get the current AWS CLI versions across your systems, using the SG inventory groupings
#get the AWS cli version from the servers in Ansible in an SG
SG=securityGroupNameofSomeSort && ansible security_group_${SG} -m shell -a 'currentAwsCliVersion=$(aws --version 2>&1 | cut -c 9-) && INSTANCE_ID=$(wget -qO- http://instance-data/latest/meta-data/instance-id) && echo $currentAwsCliVersion $INSTANCE_ID' | grep -v SUCCESS >> /tmp/jonathan_current_ver_aws_cli.txt
#get just the first and last columns, to loop through.
cat /tmp/jonathan_current_ver_aws_cli.txt | awk '{print $1 " " $NF}' >> tmp.txt && mv tmp.txt /tmp/jonathan_current_ver_aws_cli.txt
#loop though things and get the <<CLI_VERSION>> <<AWS Instance ID>> <<AWS Name tag>>
IFS='
'
for i in $( cat /tmp/jonathan_current_ver_aws_cli.txt )
do
INSTANCE_ID=$(echo "$i" | awk '{print $2}')
CLI_VER=$(echo $i | awk '{print $1}')
TAG_NAME=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" "Name=key,Values=Name" --region us-west-1 --output=text | cut -f5)
echo "$CLI_VER $INSTANCE_ID $TAG_NAME"
sleep 1
done
@jonathanhle
Copy link
Author

Sometimes, simple forloops will still get the job done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment