木偶是否有办法安装yum软件包组(例如“开发工具”),除了exec?
我今天也遇到了类似的要求,但是如果事情可以通过任何其他方式解决的话,我不是一个高pipe的粉丝。 所以我select了不同的path,并为'yumgroup'写了一个简单的自定义types。 只要将这些文件放在模块path中的任何模块中即可:
“MODULENAME / lib中/傀儡/供应商/ yumgroup / default.rb”
Puppet::Type.type(:yumgroup).provide(:default) do desc 'Support for managing the yum groups' commands :yum => '/usr/bin/yum' # TODO # find out how yum parses groups and reimplement that in ruby def self.instances groups = [] # get list of all groups yum_content = yum('grouplist').split("\n") # turn of collecting to avoid lines like 'Loaded plugins' collect_groups = false # loop through lines of yum output yum_content.each do |line| # if we get to 'Available Groups:' string, break the loop break if line.chomp =~ /Available Groups:/ # collect groups if collect_groups and line.chomp !~ /(Installed|Available)/ current_name = line.chomp.sub(/^\s+/,'\1').sub(/ \[.*\]/,'') groups << new( :name => current_name, :ensure => :present ) end # turn on collecting when the 'Installed Groups:' is reached collect_groups = true if line.chomp =~ /Installed Groups:/ end groups end def self.prefetch(resources) instances.each do |prov| if resource = resources[prov.name] resource.provider = prov end end end def create yum('-y', 'groupinstall', @resource[:name]) @property_hash[:ensure] == :present end def destroy yum('-y', 'groupremove', @resource[:name]) @property_hash[:ensure] == :absent end def exists? @property_hash[:ensure] == :absent end end
“模块名/ LIB /木偶/types/ yumgroup.rb”
Puppet::Type.newtype(:yumgroup) do @doc = "Manage Yum groups A typical rule will look like this: yumgroup { 'Development tools': ensure => present, } " ensurable newparam(:name) do isnamevar desc 'The name of the group' end end
之后,运行启用了pluginsync的puppet代理,并且可以像这样使用自定义types:
yumgroup {'Base': ensure => present, }
要么:
yumgroup {'Development tools': ensure => absent, }
您可以通过运行来查看安装的组:
puppet resource yumgroup
请享用!
这是“yumgroup”puppet资源types的定义。 它默认安装默认和强制软件包,并可以安装可选软件包。
尽pipe这个定义不能删除yum组,但它很容易实现。 我没有为自己打扰,因为在某些情况下会造成傀儡循环。
这种types需要安装yum-downloadonly rpm,我认为它只适用于RHEL / CentOS / SL 6.在我写这个的时候,yum在以前版本中的退出状态是错误的,所以'unless'参数不起作用没有扩展到grep输出。
define yumgroup($ensure = "present", $optional = false) { case $ensure { present,installed: { $pkg_types_arg = $optional ? { true => "--setopt=group_package_types=optional,default,mandatory", default => "" } exec { "Installing $name yum group": command => "yum -y groupinstall $pkg_types_arg $name", unless => "yum -y groupinstall $pkg_types_arg $name --downloadonly", timeout => 600, } } } }
我故意省略了只下载一个依赖项,因为它可能与其他人的清单冲突。 如果你想这样做,在一个单独的清单中声明yum-downloadonly包,并将其包含在这个定义中。 不要直接在这个定义中声明,否则如果你多次使用这个资源types,puppet会给出一个错误。 然后exec资源需要Package ['yum-downloadonly']。
在Packagetypes的Puppet Type Reference中我找不到任何东西,所以我问Freenode上的Puppet IRC频道(#puppet,奇怪),没有任何东西,所以我认为答案是“还没有”。
你可以通过Puppet Exec Type来处理这个事情来执行必要的组安装。 我肯定会包含一个很好的唯一或unless选项,以便它只在需要的时候执行它,或者设置为refreshonly并通过Notify触发它,以便它不会每次都运行。 如果被触发, Exectypes将在puppet客户端上本地执行命令。
我喜欢自定义资源的解决scheme,但它不是幂等的。 我的存在? function:
Puppet::Type.type(:yumgroup).provide(:default) do desc 'Support for managing the yum groups' commands :yum => '/usr/bin/yum' # TODO # find out how yum parses groups and reimplement that in ruby def self.instances groups = [] # get list of all groups yum_content = yum('grouplist') # turn of collecting to avoid lines like 'Loaded plugins' collect_groups = false # loop through lines of yum output yum_content.each do |line| # if we get to 'Available Groups:' string, break the loop break if line.chomp =~ /Available Groups:/ # collect groups if collect_groups and line.chomp !~ /(Installed|Available)/ current_name = line.chomp.sub(/^\s+/,'\1').sub(/ \[.*\]/,'') groups << new( :name => current_name, :ensure => :present ) end # turn on collecting when the 'Installed Groups:' is reached collect_groups = true if line.chomp =~ /Installed Groups:/ end groups end def self.prefetch(resources) instances.each do |prov| if resource = resources[prov.name] resource.provider = prov end end end def create yum('-y', 'groupinstall', @resource[:name]) @property_hash[:ensure] == :present end def destroy yum('-y', 'groupremove', @resource[:name]) @property_hash[:ensure] == :absent end def exists? cmd = "/usr/bin/yum grouplist hidden \"" + @resource[:name] + "\" | /bin/grep \"^Installed\" > /dev/null" system(cmd) $?.success? end end