Puppet:如何向现有文件添加行

Puppet:如何向现有文件添加行,puppet,Puppet,我试图在现有文件/etc/fuse.conf中添加一行。我试过这个 在模块目录下添加了一个文件夹和两个文件夹 sudo mkdir /etc/puppet/modules/test sudo mkdir /etc/puppet/modules/test/manifests 然后创建一个test.pp文件并添加以下行 sudo vim /etc/puppet/modules/test/manifests/test.pp file { '/etc/fuse.conf': ensure =&g

我试图在现有文件/etc/fuse.conf中添加一行。我试过这个

在模块目录下添加了一个文件夹和两个文件夹

sudo mkdir /etc/puppet/modules/test
sudo mkdir /etc/puppet/modules/test/manifests
然后创建一个test.pp文件并添加以下行

sudo vim /etc/puppet/modules/test/manifests/test.pp

file { '/etc/fuse.conf':
  ensure => present,
}->
file_line { 'Append a line to /etc/fuse.conf':
  path => '/etc/fuse.conf',
  line => 'Want to add this line as a test',
}
之后我运行了这个命令

puppet apply /etc/puppet/modules/test/manifests/test.pp
然后我打开了这个文件
/etc/fuse.conf
,文件中没有任何更改。该行未添加到文件中。我不明白我错过了什么。我该怎么做

您应该使用模板(ERB)来处理文件配置。它更容易、更干净

在以下位置检查puppet文档:

不过,还有其他选择。e、 这是一个用于文件配置的API,与Puppet集成得非常好


[]的

有几种方法可以解决这个问题。如果是ini文件,则可以使用
ini\u设置
。如果有augeas支持,您可以使用它。否则,请尝试将after参数指定给file_line。我运行了与您相同的测试,没有任何问题,只要您在您的环境中安装了
stdlib
,您就可以了

运行您概述的相同步骤的结果对我来说是成功的:

[root@foreman-staging tmp]# puppet apply /etc/puppet/modules/test/manifests/test.pp
Notice: Compiled catalog for foreman-staging.kapsch.local in environment production in 0.18 seconds
Notice: /Stage[main]/Main/File[/etc/fuse.conf]/ensure: created
Notice: /Stage[main]/Main/File_line[Append a line to /etc/fuse.conf]/ensure: created
Notice: Finished catalog run in 0.24 seconds

puppet运行了什么输出?

erb模板如何帮助向现有文件添加行?交叉发布:。请每个社区都应该诚实地回答问题,而不浪费任何人的时间。