2

Edit: The example below is correct and works perfectly. But for some reason it was not working for me at the first time and then I did vagrant provision and then everything worked perfectly.

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? I am learning puppet. So this is only for learning purpose.

3

3 Answers 3

1

For file_line the Puppet Labs standard library has to be installed.

See https://puppet.com/blog/module-of-week-puppetlabs-stdlib-puppet-labs-standard-library for more information.

-1

Try this

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':
       }
}
4
  • 1
    Does this work with Puppet 4 or something? I wasn't aware you could do bash style tests in an if statement. I tried it and it's a syntax error in Puppet 3, which is what I still use. Mar 23, 2016 at 15:32
  • I'm looking at some of my old modules, so I'm not sure about the version. I know we were using the latest, so I would assume it's v4. If you comment out the if statement, does the exec command work? Mar 23, 2016 at 15:57
  • 1
    No, you still need to tell Puppet where to find echo. You need a path attribute or fully qualify /bin/echo. Also, if you comment out the if, you'll get that line appended every time Puppet runs. OP's file_line is really the best way to do it. He just needs to troubleshoot why it isn't working. Mar 23, 2016 at 16:32
  • This is not valid puppet code.
    – user108370
    Sep 10, 2018 at 0:44
-2

You can try this:

exec {'exec_name': command => 'bash -c "echo foo_bar" >> /path/to/file', path => '/bin', }

Tried most of the of the options and they all disappointed me.

2
  • This will append the line every puppet run.
    – mzhaase
    Apr 20, 2018 at 8:45
  • @mzhaase - I've made an edit to resolve that issue
    – user108370
    Sep 11, 2018 at 7:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .