Last Updated: February 25, 2016
·
531
· xionon

Keeping your AMI at the latest version with Chef

I created some custom AMIs that I built using a Chef recipe. It took me a while to figure out why they weren't updating to the latest version.

Turns out the opscode-yum recipe had taken over /etc/yum.conf, which is where Amazon specifies that Yum should be looking in the latest version, by setting $releasever=latest

Add this to your Chef recipe, and Yum will go back to looking for the latest releases from Amazon:

ruby_block "reload-internal-yum-cache" do
  block { Chef::Provider::Package::Yum::YumCache.instance.reload }
  action :nothing
end

execute "yum-clean" do
  command "yum clean all"
  action :nothing
end

file "/etc/yum/vars/releasever" do
  content "latest"
  notifies :run, "execute[yum-clean]", :immediately
  notifies :create, "ruby_block[reload-internal-yum-cache]", :immediately
end