yum.confでアップデートしたくはないけどインストールはしたい場合のexcludeするためのrecipeとtemplate
chefでyum.confにアップデートしたくないパッケージをexcludeで記述したいけど
インストール前にexcludeしてしまうとインストールすらできなくなった。
どうにかならないかなーと考えた結果
o rpmで対象パッケージが見つかればexcludeに追加 o 見つからなければexcludeには入れない
という条件にすることで、問題は回避できることに気が付いたので
recipeとtemplateを書きました。
一応gistのURLも載せておきます。
https://gist.github.com/3906112
cookbooks/yum/recipes/default.rb
template "/etc/yum.conf" do node[:excludes] = [] source "yum.conf.erb" owner "root" mode 0644 node[:yum][:exclude].each do |exclude| if `rpm -qa | grep #{exclude}` =~ /#{exclude}/ then node[:excludes].push(exclude) end end end
cookbooks/yum/templates/default/yum.conf.erb
[main] cachedir=/var/cache/yum/$basearch/$releasever keepcache=0 debuglevel=2 logfile=/var/log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=5 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release # This is the default, if you make this bigger yum won't see if the metadata # is newer on the remote and so you'll "gain" the bandwidth of not having to # download the new metadata and "pay" for it by yum not having correct # information. # It is esp. important, to have correct metadata, for distributions like # Fedora which don't keep old packages around. If you don't like this checking # interupting your command line usage, it's much better to have something # manually check the metadata once an hour (yum-updatesd will do this). # metadata_expire=90m # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d <% if node[:excludes] then %> exclude=<%= node[:excludes].join(", ") %> <% end %>
Rubyの書き方全く知らない状態でも
1日あればどうにか動く感じにまで行くもんなんだなーって思った。
( '-')-3