我尝试用木偶编辑文件limits.com。我需要增加这些文件的行。我从:http://docs.puppetlabs.com/guides/augeas.html复制了这个示例
# /etc/puppet/modules/limits/manifests/conf.pp
define limits::conf (
$domain = "root",
$type = "soft",
$item = "nofile",
$value = "10000"
) {
# guid of this entry
$key = "$domain/$type/$item"
# augtool> match /files/etc/security/limits.conf/domain[.="root"][./type="hard" and ./item="nofile" and ./value="10000"]
$context = "/files/etc/security/limits.conf"
$path_list = "domain[.=\"$domain\"][./type=\"$type\" and ./item=\"$item\"]"
$path_exact = "domain[.=\"$domain\"][./type=\"$type\" and ./item=\"$item\" and ./value=\"$value\"]"
augeas { "limits_conf/$key":
context => "$context",
onlyif => "match $path_exact size != 1",
changes => [
# remove all matching to the $domain, $type, $item, for any $value
"rm $path_list",
# insert new node at the end of tree
"set domain[last()+1] $domain",
# assign values to the new node
"set domain[last()]/type $type",
"set domain[last()]/item $item",
"set domain[last()]/value $value",
],
}和用例:
limits::conf {
# maximum number of open files/sockets for root
"root-soft": domain => root, type => soft, item => nofile, value => 9999;
"root-hard": domain => root, type => hard, item => nofile, value => 9999;
}limits.conf内部的结果是:
#@student - maxlogins 4
root hard nofile 9999
root soft nofile 9999如何将空格或制表符放在“根硬nofile & value”值“我尝试将空格放在其中”,尝试使用regex,但不起作用。谢谢
发布于 2014-07-08 14:03:49
详细阐述了Raphink的正确答案:虽然augeas以语义的方式处理文件(它知道内容代表什么),但如果您更关心外观,还有其他选择。
在您的示例中,通过模板管理文件并对结果进行细粒度控制可能更有意义。
发布于 2014-07-08 13:54:04
您不能。Augeas自动管理空间,并且无法手动控制它们。
https://stackoverflow.com/questions/24627416
复制相似问题