Skip to content

Instantly share code, notes, and snippets.

@gaffneyc
Created April 14, 2011 00:34
Show Gist options
  • Save gaffneyc/918711 to your computer and use it in GitHub Desktop.
Save gaffneyc/918711 to your computer and use it in GitHub Desktop.
#
# Cookbook Name:: yumrepo
# Definition:: yumrepo
#
# Copyright 2010, Tippr Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# note that deletion does not remove GPG keys, either from the repo or
# /etc/pki/rpm-gpg; this is a design decision.
define :yumrepo,
:templatesource => "generic.repo.erb",
:definition => nil,
:url => nil,
:key => nil,
:url_is_mirrorlist => false,
:action => :enable do
node_config = node[:repo][params[:name]]
execute "yum -q makecache" do
action :nothing
end
ruby_block("reload-yum-cache") do
block do
Chef::Provider::Package::Yum::YumCache.instance.reload
end
end
if params[:action] == :enable
if node_config && node_config.has_key?(:enabled) && !node_config[:enabled]
log "Skipping #{node_config} due to disabled status"
else
yumkey "#{params[:key]}" if params[:key]
template("/etc/yum.repos.d/#{params[:name]}.repo") do
source(params[:templatesource])
variables({
:url => params[:url],
:shortname => params[:name],
:description => params[:definition],
:key_filename => params[:key],
:use_mirrorlist => params[:url_is_mirrorlist]
})
notifies(:run, resources(:execute => "yum -q makecache"), :immediately)
notifies(:create, resources('ruby_block[reload-yum-cache]'), :immediately)
end
end
else
file("/etc/yum.repos.d/#{params[:name]}.repo") do
action :delete
end
end
end
# vim: ai et sts=2 sw=2 ts=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment