The best way to rename a chef file

How to rename a file with a chef?

In chef doc, I found only:

  • create
  • create_if_missing
  • remove
  • click
+7
source share
2 answers

Use ruby_block and inside use :: File.Rename (src, dst). There is no file renaming in the Chef structure (or at least it wasn’t before 0.10.18).

Just an example:

ruby_block "Rename file" do block do ::File.rename(new_resource.src,new_resource.dst) end end 
+9
source

Another option if you need to rename multiple files. Checks one of the resources to see if it is running.

 ruby_block "Rename file" do block do ::Dir.glob("*/*.src").each {|i| File.rename(i, i.gsub(/(.*).src/,'\\1.dst'))}; end not_if {File.exists?("new_resource.dst")} end 
+1
source

All Articles