error2007s error2007s - 2 months ago 13
Linux Question

Chef recommended way for executing a command

I was trying to run a command

mkdir -p /path/on/disk && touch sample-file
using chef. My chef code is as below. I am on linux.

execute 'create directory' do
command 'mkdir -p /path/on/disk && touch sample-file'
end


Is there a more beter way to achieve this using chef?

Answer

Despite your laziness, here's something similar to the thing you want to achieve (your question is very unclear).

directory "/path/on/disk" do
  recursive true
end

file "/path/on/disk/sample-file" do
  content ""
  action :create_if_missing
end