Disabling logger/formater on a per-resource basis


#1

Ohai!

I love seeing the diffs during chef-client/chef-solo runs. It is such a huge aid in debugging.

That being said, there are certain resources, i.e. key files, where I don’t want this enabled.

I’m currently dealing with this like:

saved = Chef::Config[:diff_filesize_threshold]
Chef::Config[:diff_filesize_threshold] = 0
f = Chef::File::Resource.new(path, run_context)
f.action :nothing
f.content from_encrypted_databag
f.run_action(:create)
Chef::Config[:diff_filesize_threshold] = saved

It is really ugly, but it gets the job done. Taking inspiration from nod from chef-sugar, I could do something like:

def quietly(&block)
saved = Chef::Config[:diff_filesize_threshold]
Chef::Config[:diff_filesize_threshold] = 0
begin
instance_eval(&block)
rescue Exception => ex
Chef::Config[:diff_filesize_threshold] = saved
raise ex
end
Chef::Config[:diff_filesize_threshold] = saved
end

And then do:

quietly do
f = Chef::File::Resource.new(filename, run_context)
f.action :nothing
f.content from_encrypted_databag
f.run_action(:create)
end

Is there a better way of doing this? Maybe:

file filename do
action :create
content from_encrypted_databag
with {:diff_filesize_threshold => 0 }
end

Thanks.

Joe

#2

this is already being addressed
https://tickets.opscode.com/browse/CHEF-4639

On Wed, Feb 12, 2014 at 4:26 PM, Joe Nuspl nuspl@nvwls.com wrote:

Ohai!

I love seeing the diffs during chef-client/chef-solo runs. It is such a
huge aid in debugging.

That being said, there are certain resources, i.e. key files, where I
don’t want this enabled.

I’m currently dealing with this like:

saved = Chef::Config[:diff_filesize_threshold]
Chef::Config[:diff_filesize_threshold] = 0
f = Chef::File::Resource.new(path, run_context)
f.action :nothing
f.content from_encrypted_databag
f.run_action(:create)
Chef::Config[:diff_filesize_threshold] = saved

It is really ugly, but it gets the job done. Taking inspiration from nod
from chef-sugar, I could do something like:

def quietly(&block)

saved = Chef::Config[:diff_filesize_threshold]
Chef::Config[:diff_filesize_threshold] = 0
begin
instance_eval(&block)
rescue Exception => ex
Chef::Config[:diff_filesize_threshold] = saved
raise ex
end
Chef::Config[:diff_filesize_threshold] = saved

end

And then do:

quietly do
f = Chef::File::Resource.new(filename, run_context)
f.action :nothing
f.content from_encrypted_databag
f.run_action(:create)
end

Is there a better way of doing this? Maybe:

file filename do
action :create
content from_encrypted_databag
with {:diff_filesize_threshold => 0 }
end

Thanks.

Joe