linux – 如何使用puppet安装yum包组?

除了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

请享用!

相关文章

1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...
如何抑制stable_secret读取关键的“net.ipv6.conf.all.stabl...
1 删除0字节文件 find -type f -size 0 -exec rm -rf {} ...
## 步骤 1:安装必要的软件包 首先,需要确保系统已安装 `dh...