Авгей, марионетка и пробел

Я пытаюсь отредактировать файл limit.com с помощью puppet. Мне нужно добавить строки в эти файлы. Я копирую пример из: 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;

}

Результат внутри limit.conf:

#@student        -       maxlogins       4
root hard nofile 9999
root soft nofile 9999

Как я могу поместить пробел или вкладки между значениями «root hard nofile & value». Я пытаюсь поместить пробел внутри «», попробуйте с регулярным выражением, но не работает. Спасибо


person runouri    schedule 08.07.2014    source источник


Ответы (2)


Разрабатывая правильный ответ Рафинка: хотя augeas работает с файлами семантическим образом (он знает, что представляет собой контент), есть альтернативы, если вы больше заботитесь о внешнем виде.

В вашем случае может иметь смысл управлять файлом с помощью шаблона и все будет в порядке. детальный контроль результата.

person Felix Frank    schedule 08.07.2014

Вы не можете. Augeas управляет пространствами автоматически, и нет возможности управлять ими вручную.

person raphink    schedule 08.07.2014