Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to somehow get the public instance address or hostname from knife ec2 create ..., but I can't find any mechanism for doing so.

Since I'm currently using chef-solo, I've written a simple script that runs knife ec2 create with a bootstrap template to prepare the node for chef-solo. At the midpoint of that script (after knife ec2 create has finished), I need to copy and paste the public IP for the instance, which is then used to "push" to the node (copies the cookbooks, roles, data_bags, host-dna, etc up to the node and runs chef-solo).

When you bootstrap a node with chef-client and chef-server, you don't have this problem, because the new node reaches out to the chef-server and pulls it config. But I'd prefer to stick with chef-solo for now.

share|improve this question
I don't think I understand - who needs to know about the public IP address? Your bootstrap script, or the node itself in some config file? – Mike Fiedler Nov 7 '12 at 12:36
My script needs to know the public IP address. It first runs knife ec2 create ..., then pushes the chef files with rsync, then runs chef-solo via ssh. But rsync and ssh can't run unless the script knows the public IP or hostname. – nicholas a. evans Nov 12 '12 at 19:19
For what it's worth, I'm working around this at the moment with a policy of never using the same "Name" tag on more than one server at a time, and using a simple ruby fog script that pulls the list of servers and finds the server with the appropriate "Name" tag. – nicholas a. evans Nov 12 '12 at 19:20
I guess another way to do this would be to tee the output of knfe ec2 server create to a dump file, and when it completes, grep the output file for the public hostname line, etc. – Mike Fiedler Nov 13 '12 at 12:45
@nicholasa.evans Rather than have a policy about unique "name" tags, I think I'm going to get a list of active servers and sort by creation date. I'll assume the most recent is the one I want. This would seem to work so long as very few people are working with the account :) – patcon Apr 25 '13 at 15:52

Take a look at

Something like:

wget http:// /latest/meta-data/public-hostname

or change the last part to


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.