Computering is Hard

Software developer that has an affinity for Ops

Read this first

Accessing AWS instance metadata in Chef

Your AWS instance metadata is available by sending an HTTP GET request to the IP Say you wanted to get the availability zone of the instance you’re provisioning in Chef, you could simply use'').get('/latest/meta-data/placement/availability-zone').

For Ansible you should use the ec2_facts module.

View →

Getting the tags of an EC2 instance in Ansible

Say you are working on some Ansible for a client and they say to you “Hey, I really like the stuff you did but it’d be helpful if I knew what box I was SSH’d into.” since EC2 hostnames default to a dashed notation of their private IP address.

“Sure, this is 2016” you say foolishly, “someone has obviously already done this and it’s probably just an extra task”. Oh, how wrong you are.

A quick Google search later, you find out there is the ec2_facts module, which essentially acts as a wrapper around the EC2 metadata service. Surely AWS just lets you query for the tags associated with your instance through this, right? Wrong.

For some reason, even in the year 2016, Amazon has decided you have to go through their other API’s to get the tags because of course they did. So you keep digging through the Ansible modules assuming that some kind soul wrote something to do this exact thing.


Continue reading →