[chef] Re: Disabling logger/formater on a per-resource basis


Chronological Thread 
  • From: Ranjib Dey < >
  • To:
  • Subject: [chef] Re: Disabling logger/formater on a per-resource basis
  • Date: Wed, 12 Feb 2014 16:47:18 -0800

 this is already being addressed


On Wed, Feb 12, 2014 at 4:26 PM, Joe Nuspl < " target="_blank"> > 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




Archive powered by MHonArc 2.6.16.

§