augeas&木偶&空白

时间:2014-07-08 08:45:39

标签: regex puppet augeas

我尝试用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”之间添加空格或制表符 我尝试将空格放在“”中,尝试使用正则表达式但不起作用。 感谢

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

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

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