使用puppet将文本添加到文件的第一行

时间:2018-02-09 13:29:04

标签: puppet

有没有办法用Puppet将一行(或更好几行)的新文本添加到文件的第一行? (显然只做了一次)

背景是,我正在管理文件中的某些行,但我想在文件的顶部放置一次性注释,以便该文件的明确部分是"托管"。

1 个答案:

答案 0 :(得分:1)

我认为你不能使用标准的木偶资源,比如file_line或augeas。你可以做的是使用exec fx:

$file = /somefile,
$text = 'some text'
) {
  exec { "add ${text} to ${file}":
    command => "sed -i '1s/^/${text}\n/' ${file}",
    unless  => "grep '${text}' ${file}",
    path     => ['bin'],
  }    
}

有关使用bash的其他示例,请参阅How do I add text to the beginning of a file in Bash?