eww*_*ite 10 configuration-management puppet sysctl
这在CFEngine中轻而易举……但我现在处于Puppet 环境中,需要能够分配/确保/检查某些 sysctl.conf 变量。在 CFEngine 世界中,我可以简单地检查配置文件中的特定行......我在 Puppet wiki 上找到了一个对sysctl 模块的小参考,在 github中找到了一个似乎可以做我想要的项目。
但两者都没有很好的记录。我只是在寻找一种方法来编辑像net.core.rmem_default和这样的几个值net.core.wmem_max。在github 上托管的项目格式中,我的 init.pp 清单中的配置应如下所示:
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";
}
}
Run Code Online (Sandbox Code Playgroud)
通过论坛和邮件列表,似乎对 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
Run Code Online (Sandbox Code Playgroud)
关于如何以最少的痛苦完成这项工作的任何想法?
编辑:我是否受到此错误的影响?
编辑:按照 Jeff Ferland 和Puppet wiki 的建议使用 Augeas 库进行了修复。
我创建了一个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"],
}
}
Run Code Online (Sandbox Code Playgroud)
...和另一个模块来设置相关设置...
class prod_sysctl {
include sysctl
sysctl::conf {
# increase PID rollover value
"kernel.pid_max": value => "1048576";
}
}
Run Code Online (Sandbox Code Playgroud)
Jef*_*and 14
具体答案:立即来说,您正在调用 sysctl::value,但是您的 sysctl 类中未声明 value。请参阅此使用 sysctl::conf 声明的示例。没有define value,就没有可供您调用的 sysctl::value 子类。
一般答案和指导:作为Puppet 当前版本的一部分的Augeas构造(另请参阅其类型参考文档)允许在配置文件中维护行,甚至尊重上下文,因此它可以管理诸如 git 配置之类的文件。下面的示例既是为了演示功能,又是向您指出 Puppet 配置的一个很好的参考集合——维基百科服务器的实时配置存储。
[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
Run Code Online (Sandbox Code Playgroud)
上述配置文档中的一个简单示例是:
augeas { "sshd_config":
context => "/files/etc/ssh/sshd_config",
changes => [
"set PermitRootLogin no",
],
}
Run Code Online (Sandbox Code Playgroud)
因此,如果您想管理您的 /etc/sysctl.conf,请输入以下内容:
augeas { "sysctl":
context => "/files/etc/sysctl.conf",
changes => [
"set kernel.sysrq = 0",
#and whatever other lines are interesting to you
],
}
Run Code Online (Sandbox Code Playgroud)
该Augeas例子也有基于Augeus一个sysctl的类,它是类似于你在你的问题发布什么结构,这样也可以提供一些线索。