Chef Update Configuration File

I have a cook cookbook that installs nginx and installs a custom nginx.conf file. This is basically the same cookbook on Opscode and uses the cookbook_file to set the file.

If I make changes to the conf file, and then start cooking using the chef, the configuration file will not be updated. This seems like a mistake - am I doing something wrong?

+3
source share
2 answers

In a chef, the order of the commands in the recipe is the order of execution. if you saved templatefor nginx.confand it appeared after your command cookbook_file, the generated template will overwrite your file.

eg.

# cookbook file
cookbook_file "#{node[:nginx][:dir]}/nginx.conf" do
  source "my_nginx.conf"
  mode 0644
  owner "root"
  group "root"
end

# template
template "nginx.conf" do
  path "#{node[:nginx][:dir]}/nginx.conf"
  source "nginx.conf.erb"
  owner "root"
  group "root"
  mode 0644
  notifies :reload, "service[nginx]"
end

templatewill overwrite the file installed cookbook_file.

+7

, :create_if_missing, , . :create, .

+1

All Articles