How to move/copy files locally with Chef

How to copy single file First way I use file statement to copy file (compile-time check) file “/etc/init.d/someService” do owner ‘root’ group ‘root’ mode 0755 content ::File.open(“/home/someService”).read action :create end here : “/etc/init.d/someService” – target file, “/home/someService” – source file Also you can wrap ::File.open(“/home/someService”).read in lazy block … lazy { ::File.open(“/home/someService”).read } … Second … Read more

How can I change a file with Chef?

Chef actually allows and uses this. You can find an example in the opscode’s cookbooks/chef-server/recipes/default.rb: ruby_block “ensure node can resolve API FQDN” do block do fe = Chef::Util::FileEdit.new(“/etc/hosts”) fe.insert_line_if_no_match(/#{node[‘chef-server’][‘api_fqdn’]}/, “127.0.0.1 #{node[‘chef-server’][‘api_fqdn’]}”) fe.write_file end not_if { Resolv.getaddress(node[‘chef-server’][‘api_fqdn’]) rescue false } end Here’s the use-case. After the installation from source I had to uncomment lines in some … Read more