Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Say I have an app comprised of a web server and a database. If I ec2 deploy a chef client with the DB role, how can I automatically insert the IP of this new ec2 machine into my web server's config?

More generalized, how can I acquire EC2 metadata at launch time for use in attributes of other cookbooks?

I know a roundabout way to do this might be to update a dns server with shell scripts, but I'm interested to here of a solution using only chef.

share|improve this question
up vote 5 down vote accepted

You can use a properly formatted search method on the Chef recipes you run on the web server that return the node object for your DB server. Then you can get the aforementioned IPs via node["ipaddress"] οr, if you need the public IP/hostname when running on EC2, node["cloud"]["public_hostname"]/node["cloud"]["public_ipv4"]. For example, after deploying the DB server use something like:

db_servers = search(:node, 'roles:db-server').map{|n| n.attribute?('cloud') ? n['cloud']['public_ipv4'] : n['ipaddress'] }

template "web/config" do
    variables({ :dbs_ervers => db_servers })

The web server update will occur either asynchronously, whenever the Chef client runs or you can force the run by hand via manual ssh or knife ssh

share|improve this answer
Hey thanks - this will probably help a lot. – Jeff V Jan 1 '13 at 0:24
If my answer has actually solved your issue, please accept it as solved! Thanks! – Panagiotis PJ Papadomitsos Jan 8 '13 at 21:05

Chef is just a small bit in your cloud orchestration and cloud monitoring / configuration. You can use chef for configuration and nothing else. It's not for coordination of many servers.

In your case, you need Master Process, to initiate new instance launch, instance will be configured and the Master Process would update the webserver once the db instance is operational.

Many people using Chef do this mistake. Above you have correct solution. Just use it wisely. Use authentication servers too.

share|improve this answer
When you say Master Process, is that a general term or a piece of software I don't know of? – Jeff V Jan 1 '13 at 0:25
Well, you can make Master Process yourself, but there are solutions available as well, but they are more complex, so for a single use, you can make a simple loop, that it will do two things: bootstrap servers and configure them, and another one to monitor them. Then you can use e.g. database queue to control the messages. Basically you have two parts - AWS API scripting (AWS tools) and the Cloud Front (Monitoring), so basically you need to be creative. – Andrew Smith Jan 1 '13 at 1:11
And this way you dont need to do manually when you change the ip - it's just the matter how much automated you got this – Andrew Smith Jan 1 '13 at 1:12

You may want to look into AWS CloudFormation templates in combination with Chef. Bootstrap EC2 instances and spin up other AWS resources using CloudFormation i.e. control AWS using CloudFormation. Then use Chef to manage the server configuration side. I believe this is partly the functionality Andrew Smith is referring to by "Master process", the single point that you use to control the entire life-cycle. It definitely replaces AWS API scripts in Andrew's approach.

Code deployment is probably also part of this. Chef can be used for this but I don't believe this is the best way (unless you are doing some this small). Use a code build system such as Jenkins and deployment system. We currently use an in-house system but looking to move to (as we are primarily a .Net house). Assume that the code in some version control system such as Git.

Useful document:

Disclaimer: I'm no expert. Have only recently started working on our deployment design. But the architecture is looking like the above at present.

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.