编辑: 下面的例子是正确的,完美的作品。 但由于某种原因,第一次没有为我工作,然后我做了vagrant provision ,然后一切都很完美。
我试图添加一行到现有的文件/etc/fuse.conf。 我试过这个
在modules目录下添加一个文件夹两个文件夹
sudo mkdir /etc/puppet/modules/test sudo mkdir /etc/puppet/modules/test/manifests
然后创build一个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文件没有改变。 该行没有被添加到文件中。 我不明白我在这里错过了什么。 我怎样才能做到这一点? 我正在学习木偶。 所以这只是为了学习的目的。
尝试这个
file { '/etc/fuse.conf': ensure => present, }-> if "test `grep -q 'Want to add this line as a test' /etc/fuse.conf | wc -l` -eq 0" { exec { 'echo "Want to add this line as a test" >> /etc/fuse.conf': } }
你可以试试这个:
exec {'exec_name': command => 'bash -c "echo foo_bar" >> /path/to/file', path => '/bin', }
尝试了大部分的选项,他们都让我失望。