In the chef's cookbook, how to assign erb templates based on role
I am new to cook and I have a question regarding the following.
I have two servers that are using nginx. The only difference is that the configuration files are different. I am using erb templates for nginx config files.
I would assume I would need one cookbook with two erb files in the templates directory.
So let's say I have two roles server1 and server2, and in the runlist for them is nginx.
How do I configure to use the config file for server1 when using role 1? The same goes for server2.
Any tutorials on this subject?
The nginx cookbook at http://community.opscode.com/cookbooks/nginx is the perfect solution to the problem.
You only have one cookbook and one configuration template. If you need to customize something, create a role and just rewrite the attributes in your role.
There is also a definition (nginx_site), so you can use it to host sites inside the same nginx instance, which allows you to support as many sites as you want, with little issues with overall nginx configuration.
Define the roles for Server 1 and Server 2. When doing so, use override_attributes or default_attributes. To do this, you must be proactive in writing recipes. See the "Priority" section in the following link for attribute priority
http://wiki.opscode.com/display/chef/Attributes