Pages

Notifies vs. Subscribes with Chef

Jul 22, 2016
I ran into this interesting scenario recently. At uShip, we have Chef code that writes a Consul config file for a service, let's say RabbitMQ, and when the template is updated, Consul needs to be reloaded. The current code looks something like the following:

template "#{consul_config_directory}/rabbit_config.json" do
...
end

execute 'consul reload' do
  action :nothing
  subscribes :run, "template[#{consul_config_directory}/rabbit_config.json"
end

When a developer needed to add a new service, Mongo, it was not clear that another subscribes statement also needed to be added. This meant that Consul did not pick up the config properly.

This got me thinking about when to use notifies versus subscribes in Chef code. They basically do the same thing but in this case, the intention would have been a bit clearer if the template notified Consul to reload instead of the other way around. Just something to consider the next time you're trying to decide which type of notification you want
Read more ...

404 When Contacting Apt Repositories using Chef and Test Kitchen

Jan 29, 2016

Background

I'm starting a cookbook repository for an application from scratch. The cookbook will install Docker on a Linux VM and setup some default containers.

Weirdness

I ran into this weird case today where I was trying to install Git as the first package and I kept getting a 404 when trying to contact the Ubuntu Apt repositories using Test Kitchen. The odd part is that I could reach everything else so it wasn't a guest/host networking issue. Turns out, I needed to add the "apt" cookbook as a dependency so that apt-get update will be executed initially and then packages can actually be installed. Just something interesting to remember that I seem to have forgotten since the last time I ran into this.
Read more ...