从多个文件安装存储库并仅重新创建一次yum缓存

时间:2014-06-12 15:31:59

标签: chef yum

在我的一本厨师食谱中,我正在从多个文件安装一些新的存储库。

chef documentation上的

有一个如何重建缓存的示例:

execute "create-yum-cache" do
 command "yum -q makecache"
 action :nothing
end

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

cookbook_file "/etc/yum.repos.d/custom.repo" do
  source "custom"
  mode "0644"
  notifies :run, "execute[create-yum-cache]", :immediately
  notifies :create, "ruby_block[reload-internal-yum-cache]", :immediately
end

但现在让我说我必须更新多个repo文件。

execute "create-yum-cache" do
 command "yum -q makecache"
 action :nothing
end

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

cookbook_file "/etc/yum.repos.d/custom.repo" do
  source "custom"
  mode "0644"
  notifies :run, "execute[create-yum-cache]", :immediately
  notifies :create, "ruby_block[reload-internal-yum-cache]", :immediately
end

template '/etc/yum.repos.d/custom2.repo' do
  source 'custom2.repo.erb'
  owner 'root'
  group 'root'
  mode '0644'
  notifies :run, 'execute[create-yum-cache]', :immediately
  notifies :create, 'ruby_block[reload-internal-yum-cache]', :immediately
end

如何避免多次重新加载缓存?

1 个答案:

答案 0 :(得分:1)

我建议使用这本食谱https://github.com/opscode-cookbooks/yum

记住包含在metadata.rb

depends 'yum'

如何添加两个自定义存储库的示例:

yum_repository 'custom' do
  description "my custom Repo"
  baseurl "http://localhost/#{os_release}/#{arch}/stable/"
  gpgkey 'http://localhost/gpg_key'
  action :create
end

yum_repository 'custom2' do
  description "my custom Repo"
  baseurl "http://localhost2/#{os_release}/#{arch}/stable/"
  gpgcheck false
  action :create
end

如果不使用这个食谱,这里是刷新yum-cache的提供者 https://github.com/opscode-cookbooks/yum/blob/master/providers/repository.rb

抱歉我的英文! 最好的问候