linux – 如何使用puppet安装yum包组?
发布时间:2020-12-13 17:57:00 所属栏目:Linux 来源:网络整理
导读:除了exec之外,puppet是否有办法安装yum包组(例如’开发工具’)? 解决方法 我今天遇到过类似的请求,但如果事情可以通过任何其他方式解决,我不是一个执行官的粉丝.所以我选择了一条不同的路径并为’yumgroup’编写了一个简单的自定义类型.只需将这些文件放在
除了exec之外,puppet是否有办法安装yum包组(例如’开发工具’)?
解决方法
我今天遇到过类似的请求,但如果事情可以通过任何其他方式解决,我不是一个执行官的粉丝.所以我选择了一条不同的路径并为’yumgroup’编写了一个简单的自定义类型.只需将这些文件放在模块路径中的任何模块中即可:
“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 /木偶/类型/ 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代理,您可以使用这样的自定义类型: yumgroup {'Base': ensure => present,} 要么: yumgroup {'Development tools': ensure => absent,} 您可以通过运行来查看已安装的组: puppet resource yumgroup 请享用! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |