[chef] Re: Re: Re: Re: Place file only once per version


Chronological Thread 
  • From: Mike < >
  • To: " " < >
  • Subject: [chef] Re: Re: Re: Re: Place file only once per version
  • Date: Thu, 15 Aug 2013 13:39:13 -0400

Even better:

cookbook_file "foo" do
  action :create_if_missing
end

Boom.
-M

On Thu, Aug 15, 2013 at 1:23 PM, Andrew Gross < " target="_blank"> > wrote:
Whats wrong with

cookbook_file "foo" do
  action :create
  not_if { ::File.exists?("foo") }
end


On Thu, Aug 15, 2013 at 12:44 PM, Ranjib Dey < " target="_blank"> > wrote:


On Thu, Aug 15, 2013 at 9:43 AM, Ranjib Dey < " target="_blank"> > wrote:
well, you can do that using ruby stdlib, as well as low level chef api (that chef uses to make file/template/cookbookfile/remote_file [1] idempotent). But why you want to do it? If you are doing it
inside a recipe, probably its a bad idea, consider pushing them inside providers or libraries



On Thu, Aug 15, 2013 at 9:24 AM, < " target="_blank"> > wrote:
Is it possible to get a checksum of a cookbook file and store this in the attribute?

require 'Digest'
cb_filename = ? 

if node.attribute['staged_checksum'] == Digest::SHA2.file(File.new(cb_filename))
	Chef::Log.info("Already been staged")
else
	Chef::Log.info("Update staging")
	node.attribute['staged_checksum'] = Digest::SHA2.file(File.new(cb_filename))
end



inside a recipe

if node.attribute?('bar')
  Chef::Log.info('already run')
else
  ruby_block 'set_attribute' do
    block do
      nod.set['foo']='bar'
    end
  end
   file '/foo/bar' do
     content "foobar"
   end
end


On Thu, Aug 15, 2013 at 3:20 AM, < " target="_blank"> > wrote:
Hello,

Would would be the best way to only place a file once per cookbook version. It's modified and removed outside chef.

Regards
D.










Archive powered by MHonArc 2.6.16.

§