0

when am executing the below recipe am getting the error message. My requirement is I need to "Move" only certain folders(log,tmp)from source to some other location only whenever folders are available in source, if not no need to move and successfully execute my resource. whenever am executing the below resource first time with source folders(log,tmp) it will execute successfully but when to run the same resource second time it throws error message because there are no folders(log,tmp) in source. I need to successfully execute even folders(log tmp) are not present in the source. can you share yours though on this requirement?

Below is my resource :

execute "move files" do
command "mv #{node["source"]}/log tmp #{node["dest"]}"
cwd node["direct"]
only_if do File.exist?(node['source']) end
end

Error message:

mv: cannot stat âlogâ: No such file or directory

mv: cannot stat âtmpâ: No such file or directory

Raja
  • 21
  • 6
  • you mean that you want to get rid of the error message? ignoring the error then? – Jean-François Fabre Aug 23 '16 at 16:08
  • 1
    Lot of examples here http://stackoverflow.com/questions/19221252/how-to-move-copy-files-locally-with-chef – Techidiot Aug 23 '16 at 16:10
  • Can I suggest you consider the ark cookbook? It is listed as an solution in the link provided above. It's designed to support source installs and is very flexible, for example it conditionally installs, performs a security checksum and also supports a standard "make" workflow. Well worth checking, here is the link: https://supermarket.chef.io/cookbooks/ark. If you supply more details then perhaps someone can help with an example. I'm assuming this problem has been solved before. – Mark O'Connor Aug 23 '16 at 16:29

1 Answers1

0

Moving a file is not a convergent operation in the general sense so this is not recommended. A better approach would be using a link resource to create symlinks, or just deploying things in the format they should already be in (but that might require changes on the build side).

coderanger
  • 52,400
  • 4
  • 52
  • 75