首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >augeas &傀儡&空白

augeas &傀儡&空白
EN

Stack Overflow用户
提问于 2014-07-08 08:45:39
回答 2查看 1.2K关注 0票数 0

我尝试用木偶编辑文件limits.com。我需要增加这些文件的行。我从:http://docs.puppetlabs.com/guides/augeas.html复制了这个示例

代码语言:javascript
复制
# /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",
       ],
     }

和用例:

代码语言:javascript
复制
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内部的结果是:

代码语言:javascript
复制
#@student        -       maxlogins       4
root hard nofile 9999
root soft nofile 9999

如何将空格或制表符放在“根硬nofile & value”值“我尝试将空格放在其中”,尝试使用regex,但不起作用。谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-07-08 14:03:49

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

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

票数 1
EN

Stack Overflow用户

发布于 2014-07-08 13:54:04

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24627416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档