Wrong number of arguments (2 for 0..1)

Hello.

I come with another issue.
I want to create a file from template using instances variable. The attribute file looks like:

default['super']['a']['destination']		= 'a'
default['super']['a']['autorestart'] 		= 'true'
default['super']['a']['logfile_maxbytes']	= '5MB'
default['super']['a']['logfile_backups']	= 10

default['super']['b']['destination']		= 'b'
default['super']['b']['autorestart'] 		= 'true'
default['super']['b']['logfile_maxbytes']	= '6MB'
default['super']['b']['logfile_backups']	= 12

default['super']['c']['destination']		= 'c'
default['super']['c']['autorestart'] 		= 'true'
default['super']['c']['logfile_maxbytes']	= '15MB'
default['super']['c']['logfile_backups']	= 100

And the template defining in the recipe is this:

template 'super.conf' do
	path "/etc/super.conf"
	source "super.conf.erb"
	owner 'user'
	group 'user'
	mode "0644",
	variables(
		:instances => node['super']
	)
end

The error I get is this:

ArgumentError
-------------
wrong number of arguments (2 for 0..1)

Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/app/recipes/default.rb:44:in `block in from_file'
  /var/chef/cache/cookbooks/app/recipes/default.rb:39:in `from_file'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/app/recipes/default.rb:

 37:  end
 38:
 39:  template 'super.conf' do
 40:    path "/etc/super.conf"
 41:    source "super.conf.erb"
 42:    owner 'user'
 43:    group 'user'
 44>>   mode "0644",
 45:    variables(
 46:            :instances => node['super']
 47:    )
 48:  end

Running handlers:
[2016-05-24T08:18:42+00:00] ERROR: Running exception handlers
Running handlers complete
[2016-05-24T08:18:42+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 05 seconds
[2016-05-24T08:18:42+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2016-05-24T08:18:42+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2016-05-24T08:18:42+00:00] ERROR: wrong number of arguments (2 for 0..1)
[2016-05-24T08:18:42+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Any thoughts, please?

Thank you,
Gabriel

Was just a typo.

I shouldn’t have a comma in the recipe after mode… It was obvious.

Sorry to have posted it before having a better look at the code.

Gabriel

Hello

Looks like there is a comma at the end of the mode method.

Mode is expecting a single parameter but you are passing two parameters. Remove comma as below

 39:  template 'super.conf' do
 40:    path "/etc/super.conf"
 41:    source "super.conf.erb"
 42:    owner 'user'
 43:    group 'user'
 44    mode "0644"
 45:    variables(
 46:            :instances => node['super']
 47:    )
 48:  end

What is happening when Chef compiles a cookbook is that the resource settings are evaluated, when you see

mode "0644"

You are calling a method called mode with the parameter argument “0644”

Thank you,
Gabriel