joe*_*ker 10 automation linux redhat yum puppet
除了 exec 之外,puppet 是否有安装 yum 软件包组(例如“开发工具”)的方法?
Jak*_*sic 10
我今天遇到了类似的要求,但如果事情可以通过任何其他方式解决,我不喜欢执行官。所以我选择了不同的路径并为“yumgroup”编写了一个简单的自定义类型。只需将这些文件放在模块路径中的任何模块中,就是这样:
“模块名/lib/puppet/provider/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
Run Code Online (Sandbox Code Playgroud)
“模块名/lib/puppet/type/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
Run Code Online (Sandbox Code Playgroud)
之后,在启用 pluginsync 的情况下运行 puppet 代理,您可以像这样使用自定义类型:
yumgroup {'Base': ensure => present, }
Run Code Online (Sandbox Code Playgroud)
或者:
yumgroup {'Development tools': ensure => absent, }
Run Code Online (Sandbox Code Playgroud)
您可以通过运行来查看安装了哪些组:
puppet resource yumgroup
Run Code Online (Sandbox Code Playgroud)
请享用!
小智 3
我在Puppet Type Reference中找不到Package 类型的任何内容,所以我在 Freenode 上的 Puppet IRC 频道上询问(#puppet,奇怪的是),但什么也没得到,所以我认为答案是“还没有”。