Chef update config file
I have a chef cookbook which installs nginx and install a custom nginx.conf file. It's basically the same cookbook on Opscode, and uses cookbook_file to install the file.
If I make a change to the conf file, then rerun the cookbook using chef the configuration file isn't updated. This seems like a bug -- am I doing something wrong?
In chef that the order of commands in the recipe is the order of execution. if you kept the template
for the nginx.conf
and it comes after your cookbook_file
command, the generated template will overwrite your file.
e.g.
# 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
The template
would overwrite the file laid down by cookbook_file
.
In testing I have found that if you have :create_if_missing
set it will not updated the file if it the contents have changed. Set :create
and it will.
精彩评论