How do you install a yum repo?

6,338 views
Skip to first unread message

Laurence Cope

unread,
Nov 20, 2012, 4:15:13 PM11/20/12
to puppet...@googlegroups.com
Hi

I am trying to install a yum repo using puppet, so they can install a package. But i am struggling. I cannot find much help online at all. 

The only code I got working was as follows, but it works first time, but additional times it gives an error due to it being installed. Does it matter I get Resource failed messages due to it being installed, or is there a check to see if its installed, or am I using the wrong code? All other code I found online gavce errors and does not even create it. 

Thanks 

class yum
{
define packages::repo_release ($source) {
       exec { $name:
               command =>"/bin/rpm -ivh ${source}",
               creates => "/etc/yum.repos.d/${name}.repo",
       }
}

packages::repo_release { "virtualmin":
       source =>
"http://software.virtualmin.com/bleed/centos/5/i386/virtualmin-bleed-release-1.0-1.rhel.noarch.rpm",
}
}


Matthaus Owens

unread,
Nov 20, 2012, 4:19:36 PM11/20/12
to puppet...@googlegroups.com
There is a built in Puppet type for yum repos. The docs for it are
here: http://docs.puppetlabs.com/references/latest/type.html#yumrepo
You could also use a package resource with a sourch of the rpm,
something like...

package {"virtualmin":
ensure => present,
provider => rpm,
}

HTH
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/puppet-users/-/I_sDRpwl434J.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.



--
Matthaus Owens
Release Manager, Puppet Labs

Peter Bukowinski

unread,
Nov 20, 2012, 4:22:45 PM11/20/12
to puppet...@googlegroups.com
You'll want to use the yumrepo resource, documented here:


Here's an example of a basic yumrepo block:

yumrepo { "myrepo":
    descr => "My Local Repo",
    enabled => 1,
    gpgcheck => 0,
}

--
Peter

Stephen Price

unread,
Nov 20, 2012, 4:32:45 PM11/20/12
to puppet...@googlegroups.com
This is an aside, but you should really be using gpgcheck. I define repositories with yumrepo, but I also have a separate file resource to copy the gpgkey to a local directory and set the appropriate yumrepo parameters.

Jakov Sosic

unread,
Nov 20, 2012, 4:41:59 PM11/20/12
to puppet...@googlegroups.com
I have my own module for managing yum repos, and here is how it looks
like for example for EPEL repo:

# Class: yumreposd::epel
#
# This module manages EPEL repo files for $lsbdistrelease
#
class yumreposd::epel {
file { '/etc/yum.repos.d/epel.repo':
ensure => file,
mode => '0644',
owner => root,
group => root,
source =>
"puppet:///modules/yumreposd/${::operatingsystem}/${::operatingsystemrelease}/epel.repo",
require => [ Package['epel-release'], Class['yumreposd::base'] ],
}

# install package depending on major version
case $::operatingsystemrelease {
default: {}
/^5.*/: {
package { 'epel-release':
ensure => present,
provider => 'rpm',
source =>
'http://mirror.bytemark.co.uk/fedora/epel/5/i386/epel-release-5-4.noarch.rpm
',
}
}
/^6.*/: {
package { 'epel-release':
ensure => present,
provider => 'rpm',
source =>
'http://ftp-stud.hs-esslingen.de/pub/epel/6/i386/epel-release-6-7.noarch.rpm
',
}
}
}
}


Notice that I manage also files section, and distribute finished
epel.repo file.


And in the node manifest (or template that node inherits), I just do:

# yum repos
stage {'yumreposd': before => Stage['main'] }
class {'yumreposd': stage => 'yumreposd' }
class {'yumreposd::base': stage => 'yumreposd' }
class {'yumreposd::epel': stage => 'yumreposd' }
class {'yumreposd::srce': stage => 'yumreposd' }
class {'yumreposd::puppetlabs': stage => 'yumreposd' }


This ensures that all my repos are set up before any other class, so
that I don't have to maintain dependencies on repos.


If you wish I can tar the whole module and share it.


--
Jakov Sosic
www.srce.unizg.hr

Laurence Cope

unread,
Nov 20, 2012, 4:56:51 PM11/20/12
to puppet...@googlegroups.com
thanks for all that. The examples above look like some I found online (not specific to Virtualmin) which failed with errors. but maybe there were slight differences. I am off work for couple of days now, so will try these when I get back. I really appreciate it. you can tell I am new, once I get over these few hurdles I am sure I will be fine. 

@stephen yes I agree, I just wanted to cut it out until I got the rest working, one less thing that may cause errors! one step at a time :)

Stephen Price

unread,
Nov 20, 2012, 5:02:58 PM11/20/12
to puppet...@googlegroups.com
Cool, cool. If I'm installing a repo for the first time, I usually install the rpm manually on a test machine, then grab the .repo file from /etc/yum.repos.d and the referenced gpgkey, and add everything in Puppet with a custom define (which is really a wrapper around yumrepo with the additional file resource I mentioned). Makes upgrading the repo a manual process, but gives you more control.

joe

unread,
Nov 20, 2012, 5:11:09 PM11/20/12
to puppet...@googlegroups.com
Also, there is a much simpler way using your original approach. The Package type has a provider parameter that can be set to rpm. So instead of an exec, you just have a package resource that installs that rpm.

You should also look into the unless parameter to exec. It runs a command to determine if the exec needs to be run or not.
Message has been deleted
Message has been deleted

Laurence Cope

unread,
Nov 25, 2012, 10:39:11 AM11/25/12
to puppet...@googlegroups.com
Does anyone know what this error means, I get this nearly all the time when trying above and other classes out, this is where I am stuck adding a repo...

Error: /Stage[main]/Yum/Yumrepo[virtualmin]: Could not evaluate: /etc/yum.repos.d/puppet.repo:8: Can't parse 'Read more: http://www.how2centos.com/centos-6-puppet-install/#ixzz2Cgm74wkh'

I get the feeling it may mean its not a repo? This is the URL I am using, but I have used various others which I thought were repos. 

http://software.virtualmin.com/gpl/rhel/6.3/i386/ 

Steven Nemetz

unread,
Nov 25, 2012, 4:45:53 PM11/25/12
to Puppet-Users Mailing List

The error say that on line 8 of file /etc/yum.repos.d/puppet.repo there is something that it cannot interpret. Usually some type of syntax error, but it could be something else.
Your first step is to look at that file on the host that is getting the error and see what is there. If it is not obvious, post that section of the file and with a note of which line it is complaining about.

Steven



Date: Sun, 25 Nov 2012 07:39:11 -0800
From: amityweb...@gmail.com
To: puppet...@googlegroups.com
Subject: [Puppet Users] Re: How do you install a yum repo?
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/dpdGPcm2nF0J.
Message has been deleted

Laurence Cope

unread,
Nov 25, 2012, 4:48:02 PM11/25/12
to puppet...@googlegroups.com
Dont worry about my error! I found it. Eventually! I was following this tutorial:
http://www.how2centos.com/centos-6-puppet-install/

And somehow, during some copying and pasting the [puppetlabs] repo text, the line "Read more http://www.how2centos.com/centos-6-puppet-install/#ixzz2Cgm74wkh" ended up in my puppet.repo file and was throwing this error. 

So fixed now and seems I can installed repos. 

Laurence Cope

unread,
Nov 25, 2012, 5:15:37 PM11/25/12
to puppet...@googlegroups.com
Thanks Steven. The error was the line that said "Read more..." but I thought that was a Puppet output telling me to read more about the error, I got really confused! Once I looked at puppet.repo it was immediately obvious!
Thanks
Reply all
Reply to author
Forward
0 new messages