简体   繁体   English

如何使用Puppet正确安装存储库

[英]How to properly install a repository with Puppet

I'm struggling to install a repository with Puppet, specifically the zabbix repository. 我正在努力用Puppet安装存储库,特别是zabbix存储库。 I got the zabbix repository for CentOS 7 from here , and am using the following: 我从这里获得了CentOS 7的zabbix存储库,并且正在使用以下内容:

http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

I tried using the following Puppet code to install it on my node, and it didn't seem to work: 我尝试使用以下Puppet代码将其安装到我的节点上,但似乎无法正常工作:

node 'puppet-agent' {
    include importRepos
    package { 'php':
        ensure => "installed",
    }
    package { 'zabbix-agent':
        ensure => "installed", 
    }

}

class importRepos {
    yumrepo { "zabbix":
        baseurl => "http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm",
        descr => "Zabbix repo to install Zabbix client on CentOS 7",
        enabled => 1,
        gpgcheck => 1
        }
}

The error I got was: 我得到的错误是:

...
Execution of '/usr/bin/yum -d 0 -e 0 -y install zabbix-agent' returned 1: Delta RPMs disabled because /usr/bin/applydeltarpm not installed.


Error downloading packages:
  zabbix-agent-3.4.15-1.el7.x86_64: [Errno 256] No more mirrors to try.

I tried installing the deltarpm package, and now I get this error: 我尝试安装deltarpm软件包,现在出现此错误:

...
Error downloading packages:
  zabbix-agent-3.4.15-1.el7.x86_64: [Errno 256] No more mirrors to try.
Error: /Stage[main]/Main/Node[puppet-agent]/Package[zabbix-agent]/ensure: change from purged to present failed: Execution of '/usr/bin/yum -d 0 -e 0 -y install zabbix-agent' returned 1: No Presto metadata available for zabbix


Error downloading packages:
  zabbix-agent-3.4.15-1.el7.x86_64: [Errno 256] No more mirrors to try.

I then did a yum clean all and tried again and now I get this error: 然后,我做了一个yum clean all,然后再次尝试,现在出现此错误:

Error: Execution of '/usr/bin/yum -d 0 -e 0 -y install zabbix-agent' returned 1: One of the configured repositories failed (Zabbix repo to install Zabbix client on CentOS 7),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

It recommends that I disable the repo, so I'm not sure what mistake I made but for some reason it doesn't seem that the repo is valid based on how I configured it.Does anyone know how I can get the zabbix repo to work in Puppet so that I can install the zabbix agent? 它建议我禁用该存储库,所以我不确定我犯了什么错误,但是由于某种原因,基于我的配置,该存储库似乎无效。有人知道我如何获得zabbix存储库吗?在Puppet中工作,以便我可以安装zabbix代理?

You must always bear in mind that Puppet's DSL is focused on the machine-state details to be managed, not the details of changing machine state. 您必须始终牢记,Puppet的DSL专注于要管理的机器状态详细信息,而不是更改机器状态的详细信息。 That would have helped you avoid misinterpreting the docs for the Yumrepo resource type . 这样可以帮助您避免误解Yumrepo资源类型的文档

Specifically, the baseurl property of of that type corresponds directly to a per-repository Yum configuration parameter of the same name. 具体来说,该类型的baseurl属性直接对应于同名的每个存储库Yum配置参数。 That parameter designates the base URL of the repository (so probably http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/ in your case) not the name of a package to install to obtain the repo definition. 该参数指定存储库的基本URL(因此,您可能使用的是http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/ ),而不是要获取该仓库定义的软件包名称。

If you like, you can do without the package altogether, and instead configure the repository strictly via a Yumrepo resource. 如果愿意,您可以完全不使用该软件包,而是通过Yumrepo资源严格配置存储库。 If you want to manage it at least partially via the package, however, then you have a chicken & egg problem: where do you get the package in order to create a repo definition for the repo containing the package? 但是,如果要至少部分地通过软件包来管理它,则会遇到鸡与蛋的问题:在哪里可以得到该软件包,以便为包含该软件包的存储库创建存储库定义? There are two main alternatives: 有两种主要选择:

  • Perform the initial configuration of the repository as part of your provisioning process, outside the scope of Puppet, by manually installing the package. 通过手动安装软件包,在Puppet范围之外,在供应过程中执行存储库的初始配置。 You can thereafter both tweak the repo configuration and update the repository-release package via Puppet. 之后,您既可以调整存储库配置,也可以通过Puppet更新存储库发行包。

  • Put copies of repository-release packages into your own local package repo (you do have one, don't you?). 将版本库发布的软件包的副本放入您自己的本地软件包库中(您确实有一个,不是吗?)。 Configure that repo as you like, allowing Puppet to install repo-release packages from there. 根据需要配置该存储库,从而允许Puppet从那里安装存储库发布版本的软件包。

Either way, if you're managing both release package and repo details via Puppet, then that part looks something like this: 无论哪种方式,如果您都通过Puppet管理发行包和回购详细信息,则该部分看起来像这样:

class importRepos {
  package { 'zabbix-release' ensure => 'latest' }

  yumrepo { "zabbix":
    # Most repo properties probably should not be managed
    enabled  => 1,
  }
}

Having done that, you may also need to be a little mindful of class and resource ordering. 完成此操作后,您可能还需要对类和资源排序有所注意。 That's far too a big topic to cover in one SO answer, but for your particular case, given that you are declaring packages directly in a node block instead of via a class, my recommendation would be to declare the appropriate dependency among the relevant package's properties: 这是一个太大的主题,无法涵盖在一个SO答案中,但是对于您的特殊情况,鉴于您是直接在节点块中声明包而不是通过类声明包,我的建议是在相关包的属性之间声明适当的依赖关系:

node 'puppet-agent' {
  include importRepos

  package { 'php':
    ensure => "installed",
  }

  package { 'zabbix-agent':
    ensure  => "installed",
    require => Yumrepo['zabbix'],  # <--- this
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM