Puppet: how to add a line to an existing file

时间:2016-03-16 19:40:20

标签: puppet

I am trying to add a line to an existing file /etc/fuse.conf. I tried this

added a folder two folders under modules directory

sudo mkdir /etc/puppet/modules/test
sudo mkdir /etc/puppet/modules/test/manifests

Then created a test.pp file and added following lines

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',
}

After that I ran this command

puppet apply /etc/puppet/modules/test/manifests/test.pp

Then I opened this file /etc/fuse.conf and there was no change in the file. The line was not added to the file. I don't understand what I am missing here. How can I do this?

3 个答案:

答案 0 :(得分:0)

您应该使用模板(ERB)来处理文件配置。它更容易,更清洁。

检查木偶文档: https://docs.puppetlabs.com/puppet/latest/reference/lang_template.html

但还有其他选择。例如Augeas是一个用于文件配置的API,并且与Puppet很好地集成。 http://augeas.net/index.html

[]的

答案 1 :(得分:0)

有几种方法可以解决这个问题。如果是ini文件,您可以使用RECORDS。如果它得到了augeas的支持,你可以使用它。否则,请尝试将after参数指定为file_line

答案 2 :(得分:0)

有趣。我在没有问题的情况下运行了相同的测试,只要你在你的环境中安装了stdlib,你就可以了。

https://forge.puppet.com/puppetlabs/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

你的傀儡输出了什么?