简体   繁体   中英

repo file formatting with puppet yumrepo resource type

I am attempting to use puppet to manage my /etc/yum.repos.d/CentOS-Base.repo file. The built-in puppet yumrepo resource type is adding the baseurl value that is expected, but it's placing the line after the comment for the next repo in the file, [updates].

How can I force puppet to format the [base] repo more prettily? Ideally I would like puppet to replace the commented baseurl entry with the line after "#released updates", as seen below.

[base]
name=CentOS-$releasever - Base
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
baseurl=http://SERVERXXX/distros/CentOS/$releasever/os/$basearch/
[updates]

Here is the puppet code snippet:

class repos { case $operatingsystem { "CentOS", "RedHat": { yumrepo { "base": baseurl => 'http://SERVERXXX/distros/CentOS/$releasever/os/$basearch/', gpgcheck => "1", gpgkey => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6", mirrorlist => absent, }

The yumrepo type (as it stands) is not capable of any formatting.

You might be able to combine it with augeas to do some tinkering, but it's likely not worth the hassle.

Your mileage will likely be best when each repository has a file for itself. But the settings will still be ordered rather chaotically.

your best bet is to use another resource as part of the class to add the comment line (augues, line in file, template) among other are several ways to handle this, or just use the descr attribute so that the manifest and its effect are much clearer and you do not need the extra comment then as the name will be more informative.

class repos {
yumrepo { 'epel-testing-source':
  ensure         => 'present',
  descr          => 'Extra Packages for Enterprise Linux 6 - Testing - $basearch - Source',
  enabled        => '0',
  failovermethod => 'priority',
  gpgcheck       => '1',
  gpgkey         => 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6',
  mirrorlist     => 'https://mirrors.fedoraproject.org/metalink?repo=testing-source-epel6&arch=$basearch',
}

}

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