简体   繁体   中英

How to properly install a repository with Puppet

I'm struggling to install a repository with Puppet, specifically the zabbix repository. I got the zabbix repository for CentOS 7 from here , and am using the following:

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:

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:

...
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:

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?

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. That would have helped you avoid misinterpreting the docs for the Yumrepo resource type .

Specifically, the baseurl property of of that type corresponds directly to a per-repository Yum configuration parameter of the same name. 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.

If you like, you can do without the package altogether, and instead configure the repository strictly via a Yumrepo resource. 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. You can thereafter both tweak the repo configuration and update the repository-release package via 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.

Either way, if you're managing both release package and repo details via Puppet, then that part looks something like this:

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:

node 'puppet-agent' {
  include importRepos

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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