sous-chefs / logrotate

Development repository for the logrotate cookbook

Home Page:https://supermarket.chef.io/cookbooks/logrotate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parameter 'cookbook' doesn't work

nullck opened this issue · comments

Hello guys,

I'm using your cookbook for a long time, and now I noticed one issue:

"NoMethodError

undefined method `cookbook' for Custom resource logrotate_app from cookbook logrotate

Cookbook Trace:

/tmp/chef-solo/cookbooks/logrotate-scup/recipes/default.rb:30:in block in from_file' /tmp/chef-solo/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_builder.rb:90:ininstance_eval'
/tmp/chef-solo/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_builder.rb:90:in build' /tmp/chef-solo/cookbooks/logrotate-scup/recipes/default.rb:29:infrom_file'

Relevant File Content:

/tmp/chef-solo/cookbooks/logrotate-scup/recipes/default.rb:

23:
24: if node[:logrotate_scup][:sudo_enabled]
25: include_recipe "logrotate-scup::sudo_options"
26: else
27:
28: if node[:logrotate_scup][:app][:name] == "plataforma"
29: logrotate_app node['logrotate_scup']['app']['name'] do
30>> cookbook 'logrotate'
31: path node['logrotate_scup']['app']['path']
32: frequency node['logrotate_scup']['app']['frequency']
33: rotate node['logrotate_scup']['app']['rotate']
34: create node['logrotate_scup']['app']['create']
35: end
36: end
37:
38: if node[:logrotate_scup][:app][:name] != "plataforma"
39: logrotate_app node['logrotate_scup']['app']['name'] do
"

I created one cookbook that I'm using by interface, my parameters are:

logrotate_app node['logrotate_scup']['app']['name'] do
cookbook 'logrotate'
path node['logrotate_scup']['app']['path']
frequency node['logrotate_scup']['app']['frequency']
rotate node['logrotate_scup']['app']['rotate']
create node['logrotate_scup']['app']['create']
size node['logrotate_scup']['app']['size']
end

The tag v1.7.0 still works well, but code of master branch has this issue.

Apologies this broke you, this was an intentional change in the 2.0 refactor. Are you always calling cookbook with the argument logrotate? If so, you can likely remove the cookbook attribute from the call sites. If you are supplying custom templates in some cases, would you mind sharing your use cases so that we could see if we can support them in this cookbook via some other means? I'd prefer not to allow users to set their own template because it means we are always tied to maintaining the representation of data we pass to the template resource.

all the examples in the README use it.

breaks our setup, as we heavily use the cookbook attribute (not with defaults, of course)

@rmoriz Do your templates use anything not included here: https://github.com/stevendanna/logrotate/blob/master/resources/app.rb#L49-L56

If not, I could re-add the attribute. I removed it because exposing it basically makes the data we pass into it an API that needs to be supported. But I think that hash won't change too much in the future.

@rmoriz @nullck I just pushed a change to master to re-add the cookbook attribute. Let me know if that works for you.

and please release updated cookbook to supermarket

@scopenco I will release it to supermarket hopefully today or tomorrow. I would like some confirmation from the people who have spoken up about this that the current interface will work for them before releasing it so that we don't have to change that interface a bunch.

Test coverage for this added here: 2e069e5

keep in mind when making these types of breaking changes - it helps to keep the old around for a while and add WARNING's about the option being deprecated. The end user who gets the error might not be the one who's directly consuming your cookbook - it could be 3 or 5 levels of dependancies deep. (in my case, it's the openresty cookbook - which I wrap, but don't maintain.)

for me, the fix now is going to be to version lock to 1.9.2 in my wrapper cookbook. :(

Relevant File Content:
----------------------
/opt/chefprov/Provisioning/berkshelf-cookbooks/openresty/recipes/commons_conf.rb:

100:
101:    # Log rotation
102:    logrotate_app 'openresty' do
103:      path "#{node['openresty']['log_dir']}/*.log"
104:      enable true
105:      frequency 'daily'
106:      rotate node['openresty']['logrotate_days']
107>>     cookbook 'logrotate'
108:      create "0644 #{node['openresty']['user']} adm"
109:      options node['openresty']['logrotate_options']
110:      postrotate "test -f #{node['openresty']['pid']} && kill -USR1 $(cat #{node['openresty']['pid']})"
111:    end
112:
113:  end
114:

I've shipped 2.1.0 to the community site. Please let me know if any of y'all still run into problems.

@keen99 +1 I did that for a few other options but missed it for this one. I had the mistaken assumption that this option was barely used but I think that it being in the README meant that it was used in lots of places even when people are just setting it to the default value.

👍 thanks - working for me!