0

我尝试使用 puppet 编辑文件 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

如何将空格或制表符放在值“root hard nofile & value”之间我尝试将空格放在“”中,尝试使用正则表达式但不起作用。谢谢

4

2 回答 2

2

你不能。Augeas 自动管理空间,无法手动控制它们。

于 2014-07-08T13:54:04.763 回答
1

详细说明 Raphink 的正确答案:虽然augeas以语义方式处理文件(它知道内容代表什么),但如果您更关心外观,还有其他选择。

在您的情况下,通过模板管理文件并对结果进行细粒度控制可能更有意义。

于 2014-07-08T14:03:49.753 回答