Questions tagged [chef-recipe]

A recipe is the most fundamental configuration element in Chef. Recipes specify which resources to manage and the order in which those resources will be applied.

A recipe is the fundamental configuration element in the Chef configuration-management tool. Recipes specify which resources to manage and the order in which those resources will be applied. A recipe:

  • Is authored using Ruby, which is a programming language designed to read and behave in a predictable manner
  • Is mostly a collection of resources in a Ruby syntax with some helper code around it
  • Must define everything that is required to configure part of a system
  • Must be stored in a cookbook
  • May be included in a recipe
  • May use the results of a search query and read the contents of a data bag (including an encrypted data bag)
  • May have a dependency on one (or more) recipes
  • May be tagged to facilitate the creation of arbitrary groupings that exist outside of the normal naming conventions an organization may have
  • Must be added to a run-list before it can be used by the chef-client Is always executed in the same order as listed in a run-list
1255 questions
70
votes
2 answers

Should I use include_recipe or add the recipe to run_list?

Trying to figure out the best approach for a large project. When is it appropriate to add recipes within a recipe by using include_recipe as opposed to adding the recipe to the run_list? Is there a good rule of thumb?
Micah
  • 111,873
  • 86
  • 233
  • 325
43
votes
3 answers

Overriding attributes in the recipe

Let's say I have a default attribute in a cookbook: default.nginx_upstreams = { 'service1' => ['service1.server.com'], 'service2' => ['service2.server.com'], } Then it gets modified and overridden in roles and environments until it finally…
Igor Serebryany
  • 3,307
  • 3
  • 29
  • 41
35
votes
5 answers

How can you use a Chef recipe to set an environment variable?

How can you use a Chef recipe to set an environment variable? I need to set an environment variable using a Chef recipe. Can you provide an example of how to accomplish this?
Brandon
  • 6,832
  • 11
  • 38
  • 50
29
votes
4 answers

How can I change a file with Chef?

I have 7 files and 1 war. I need to change values when I deploy them. I have this: ##usuario #alfresco.user=***** alfresco.user=******** ##pass #alfresco.password=…
23
votes
3 answers

Node Name in Chef Template?

I've been trying to figure out how to get the node's name (knife bootstrap -N) into a template. I've tried a dozen different ideas and haven't found anything that works yet. Does anyone know how to access this from a Chef recipe? Also -- is there…
erikcw
  • 10,787
  • 15
  • 58
  • 75
18
votes
9 answers

How to query cookbook versions on a node?

Usage case: The DevOps team launched a node sometime ago, and my team would like to know what's the version(s) of one/several cookbook(s) being used in the run_list. Our DevOps team is firefighting so we'd like to find a way to be…
digit plumber
  • 1,140
  • 2
  • 14
  • 27
17
votes
4 answers

Why can't chef resolve my cookbooks?

Intro I am learning Chef to automate the server management at work. I downloaded chefdk 3.0 from here and now I am trying to build my first cookbook using chef. Important I am using this in a Windows environment for testing purpose, I do expect it…
JSBach
  • 4,679
  • 8
  • 51
  • 98
17
votes
2 answers

DRY within a Chef recipe

What's the best way to do a little DRY within a chef recipe? I.e. just break out little bits of the Ruby code, so I'm not copying pasting it over and over again. The following fails of course, with: NoMethodError: undefined method `connect_root' for…
DragonFax
  • 4,625
  • 2
  • 32
  • 35
15
votes
2 answers

Need to refactor to the new Ruby 1.9 hash syntax

I have a recipe that has the following code that is failing a lint test: service 'apache' do supports :status => true, :restart => true, :reload => true end It fails with the error: Use the new Ruby 1.9 hash syntax. supports :status => true,…
TyMac
  • 783
  • 2
  • 9
  • 32
15
votes
3 answers

How to lazily evaluate an arbitrary variable with Chef

I'm writing a Chef recipe to install our application code and execute it. The recipe needs to be particular about the directory this code ends up in (for running templates, setting log forwarding etc.). Thus the directory itself pops up in a lot of…
Patrick M
  • 10,547
  • 9
  • 68
  • 101
15
votes
5 answers

What is the correct way to check for the existence of a nested attribute in Chef?

There are multiple ways to check for the existence of a nested attribute in chef, and I'm not sure which is correct/best, and if any will result in empty attributes being stored on the node: node[:parent] and…
borntyping
  • 2,931
  • 2
  • 23
  • 30
14
votes
1 answer

Check if chef is running as chef-solo

I'm using Vagrant and chef-solo to test my cookbooks, but I have one particular recipe that requires chef-server (it uses search). I'd like my default recipe to look like the following: include_recipe 'some_recipe' include_recipe…
AndrewF
  • 6,852
  • 7
  • 29
  • 27
13
votes
5 answers

Using a Chef recipe to append multiple lines to a config file

I'm trying to create a Chef recipe to append multiple lines (20-30) to a specific config file. I'm aware the recommended pattern is to change entire config files rather than just appending to a file, but I dislike this approach for multiple…
Gui Ambros
  • 1,045
  • 1
  • 12
  • 20
12
votes
1 answer

Platform neutral way to create a temporary file in Chef Recipe

I have a chef recipe that uses a template to generate and xml document. The location of that document on the file system is not important; the location simply needs to be handed to a command line tool which will read the file and use it to…
Kenneth Baltrinic
  • 2,941
  • 2
  • 28
  • 45
12
votes
1 answer

Chef Attributes: does file name matter?

When I create attributes in my cookbook's attributes /attributes/default.rb things work fine. If I add a recipe to my cookbook, say /recipes/dofubar.rb, I expect that attributes defined in /attributes/dofubar.rb to be loaded. They do not appear to…
Code Silverback
  • 3,204
  • 5
  • 32
  • 39
1
2 3
83 84