Search code examples
chef-infracookbook

remove chef cookbook_file if not exist in cookbook


I have few files in cookbook under files (blah-cookbook/files/default/file01*.xml)

When I run chef-client, it populates on destination directory (/etc/app/file01*.xml) - Good so far.

cookbook_file "/tmp/file01.xml" do
  source "file01"
  owner "root"
  group "root"
  mode 00600
  action :create
end

Lets say I remove few files from cookbook files, how do I make it reflect on destination directory ? I would like to have identical files on destination direcotry (/etc/app/file) and cookbook files (blah-cookbook/files/default/file01.xml). No more, no less.


Solution

  • You might want to be using a remote_directory resource for this, but more likely you should use some other kind of file packaging/distribution system as Chef's internal tools for it are incredibly minimal. A shared git repository (with a git resource) or a deb/RPM package (with package resource) are both popular options.