Rusty Robot
Rusty Robot

Reputation: 1365

Best way to rename a file with chef

How can I rename a file with chef?

In the chef doc I found only:

Upvotes: 7

Views: 8560

Answers (2)

kamal079
kamal079

Reputation: 68

Another option if you need to rename multiple files. Checks one of the resource to know if it already ran.

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

Upvotes: 1

Sacx
Sacx

Reputation: 6392

Use ruby_block and inside use ::File.Rename(src,dst). Chef framework doesn't have file rename (or at least didn't had until 0.10.18).

Just an example:

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

Upvotes: 10

Related Questions