Created
April 29, 2016 21:22
-
-
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
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
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes, simple forloops will still get the job done.