简体   繁体   English

使用puppet yumrepo资源类型的repo文件格式

[英]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. 我正在尝试使用p来管理我的/etc/yum.repos.d/CentOS-Base.repo文件。 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]. 内置的puppet yumrepo资源类型正在添加期望的baseurl值,但它将行放置在文件中下一个回购的注释[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. 理想情况下,我希望木偶用“ #released updates”之后的行替换注释的baseurl条目,如下所示。

[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, } 类存储库{ 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. yumrepo类型(按yumrepo )无法进行任何格式化。

You might be able to combine it with augeas to do some tinkering, but it's likely not worth the hassle. 您可能可以将其与augeas结合使用以进行一些修补,但这可能不值得麻烦。

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. 最好的选择是使用其他资源作为类的一部分来添加注释行(augaus,文件中的行,模板),其中的几种方法可以解决此问题,或者只是使用descr属性,以便清单及其效果是更清晰,您不需要多余的注释,因为名称将提供更多信息。

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',
}

} }

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

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