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

I'm looking at the and under "Execute" in "Execute a command using a template", they call template with parenthesis around the argument. Just a handful of statements earlier, they call execute sans parenthesis. For the rest of the document, template is called without parenthesis. Is there a reason for this inconsistency?

execute "forward_ipv4" do
  command "echo > /proc/.../ipv4/ip_forward"
  action :nothing

template( "/etc/file_name.conf" ) do
  source "routing/file_name.conf.erb"
  notifies :run, 'execute[forward_ipv4]', :delayed
share|improve this question
up vote 1 down vote accepted

I've never seen that syntax/style before until you pointed it out. It's completely unnecessary and confusing to use parentheses in that situation. Just specifying the template and the filename is sufficient.

share|improve this answer
Hmm, I guess I'll go bring this inconsistency in documentation up in their issues tracker then. Thanks! – crazysim Jan 24 '13 at 18:47
And done: – crazysim Jan 24 '13 at 19:03

Chef recipes are written in Ruby, and the DSL uses #method_missing for defining resources in recipes.

Thus, each resource is a method, which takes a single argument (a string, the name), and a block (the parameters).

Parentheses are optional around the arguments in Ruby, and there is much written about whether to use them on the internet. While it doesn't matter whether you use them in Chef resources, most often they are omitted.

However, if you wish to write a resource on a single line, you'll need parentheses:

execute "echo Hello" { action :nothing }

SyntaxError: (irb#1):1: syntax error, unexpected '{', expecting $end
execute "echo Hello" { action :nothing }

execute("echo Hello") { action :nothing }

 => <execute[echo Hello] @name: "echo Hello" @noop: nil @before: nil
 @params: {} @provider: nil @allowed_actions: [:nothing, :run]
 @action: [:nothing] @updated: false @updated_by_last_action: false
 @supports: {} @ignore_failure: false @retries: 0 @retry_delay: 2
 @source_line: "(irb#1):2:in `irb_binding'" @elapsed_time: 0
 @resource_name: :execute @command: "echo Hello" @backup: 5 @creates:
 nil @cwd: nil @environment: nil @group: nil @path: nil @returns: 0
 @timeout: nil @user: nil @umask: nil @cookbook_name: nil
 @recipe_name: nil>

(action nothing here is just to show an example)

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.