使用Puppet设置sysctl.conf参数

这在CFEngine中是一件轻而易举的事情 ……但是我现在在一个Puppet环境中 ,需要能够分配/确保/检查某些sysctl.confvariables。 在CFEngine世界中,我可以简单地检查configuration文件中的特定行……我已经find了Puppet wiki上的sysctl模块的一个小引用,并且在github上看到了一个项目,它可以做我想做的事情。

但是都没有真正的文件logging。 我只是寻找一种方式来编辑像net.core.rmem_defaultnet.core.wmem_max两个值。 在github上托pipe的项目格式中,init.pp清单中的configuration应该如下所示:

 class sysctl { sysctl::value { "net.core.rmem_default": value => "9000000"; "net.core.wmem_default": value => "9000000"; "net.core.rmem_max": value => "16777216"; "net.core.wmem_max": value => "16777216"; } } 

通过论坛和邮件列表,似乎对Puppet插件和模块之间的差异感到困惑。 这些条款几乎可以互换使用…我最终需要在我的客户端启用pluginsync,以便通过一些毛茸茸的错误。 我以为这是一个模块!

目前的客户端错误:

 info: Loading downloaded plugin /var/lib/puppet/lib/puppet/type/sysctl.rb info: Loading downloaded plugin /var/lib/puppet/lib/puppet/provider/sysctl/parsed.rb err: Could not retrieve catalog from remote server: Error 400 on SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type sysctl::value at /var/lib/puppet/base/modules/sysctl/manifests/init.pp:12 on node shimano.deore.abc.net warning: Not using cache on failed catalog err: Could not retrieve catalog; skipping run 

有关如何以最less的痛苦完成这个任何想法?

编辑:我受这个错误的影响?

编辑:修复使用由Jeff Ferland和Puppet wikibuild议的Augeas库。

我创build了一个sysctl模块…

 class sysctl { # nested class/define define conf ( $value ) { # $name is provided by define invocation # guid of this entry $key = $name $context = "/files/etc/sysctl.conf" augeas { "sysctl_conf/$key": context => "$context", onlyif => "get $key != '$value'", changes => "set $key '$value'", notify => Exec["sysctl"], } } file { "sysctl_conf": name => $operatingsystem ? { default => "/etc/sysctl.conf", }, } exec { "/sbin/sysctl -p": alias => "sysctl", refreshonly => true, subscribe => File["sysctl_conf"], } } 

…和另一个模块来设置相关的设置…

 class prod_sysctl { include sysctl sysctl::conf { # increase PID rollover value "kernel.pid_max": value => "1048576"; } } 

具体的答案:马上说,你调用的是sysctl :: value,但是在你的sysctl类中没有声明值。 看到这个使用sysctl :: conf声明的例子 。 如果没有define value ,则不需要调用sysctl :: value子类。


一般的答案和指导:作为当前版本的Puppet的一部分的Augeas构造(参见其types参考文档 )允许在configuration文件中维护行,甚至可以考虑上下文,因此它可以pipe理诸如gitconfiguration之类的文件。 下面的例子是为了展示function,并指出你一个伟大的参考集合的Puppetconfiguration – 维基百科服务器的实时configuration存储。

 [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = https://gerrit.wikimedia.org/r/p/operations/puppet [branch "production"] remote = origin merge = refs/heads/production 

上述configuration文件中的一个简单例子就是:

 augeas { "sshd_config": context => "/files/etc/ssh/sshd_config", changes => [ "set PermitRootLogin no", ], } 

所以,如果你想pipe理你的/etc/sysctl.conf,input以下内容:

 augeas { "sysctl": context => "/files/etc/sysctl.conf", changes => [ "set kernel.sysrq = 0", #and whatever other lines are interesting to you ], } 

Augeas的例子也有一个基于Augeus的类的sysctl类的构造,类似于你在问题中发布的内容,所以也可以说明一些。

过去,我使用过RHEL5: puppet-sysctl这个模块

要使用它,你必须安装模块到你的模块文件夹(可能是/ etc / puppet / modules / sysctl)在你的节点上包括这个类:(包括sysctl)然后调用def资源,像这样:

 class s_sysctl::rhel_defaults { include sysctl # Controls IP packet forwarding sysctl::set_value { "net.ipv4.ip_forward": value => 0 } # Controls source route verification sysctl::set_value { "net.ipv4.conf.default.rp_filter": value => 1 } } 

所以你可能想知道,这段代码实际上在哪里? 我喜欢像这样组织我的木偶树:

 site.pp -> nodes.pp -> roles.pp -> /etc/puppet/site-modules/s_sysctl -> /etc/puppet/modules/sysctl 

这样,站点模块包含hiera数据或可调参数,模块保持通用,可插入和“模块化”。

只要你不需要改变这个值(或者用附加新值的行来满足),你可以使用Common的 line 。 当您更改值时,您可以使用一对present / absentconfiguration。

要更改该值(假定该行已经存在),可以在同一个模块中使用replace

或者你可以看看这些定义是如何写出来的,以使其适合于你的任务 – 我认为,我认为它简单而通用,应该由默认types的Puppet提供。

那么,为什么不呢? 因为木偶希望你完全pipe理你正在pipe理的东西。 也就是说,你应该分发整个 sysctl文件,而不是只添加或删除一个值。 我并不是说这一定是一件容易的事情,但如果你能摆脱这种困境,那么这就是最简单的方法。