11

I only want to exec following command when file (/usr/local/bin/papply) does not exist. not sure what to put there.

    exec { 'git add url':
        command =>'git remote add origin https://github.com/testing/puppet.git',
        require => Exec['git init'],
        cwd => '/home/vagrant/django',
        user => 'vagrant',
        onlyif => "not sure what to put here"
    }

4 Answers 4

24

Have you tried this?

onlyif => "test ! -f /usr/local/bin/papply"

Not sure if Puppet can use the '!' character

Perhaps a better alternaltive:

creates => '/usr/local/bin/papply'

even if i don't like the fact that the command doesn't really creates the file

4
  • not working, got this error message. Could not evaluate: Could not find command '!'
    – qinking126
    Dec 4, 2013 at 1:22
  • And this: onlyif => "test ! -f /usr/local/bin/papply" Dec 4, 2013 at 1:27
  • creates => '/usr/local/bin/papply' works, thank you. let me test your updates, see if htat one works.
    – qinking126
    Dec 4, 2013 at 1:36
  • 1
    onlyif => "test ! -f /usr/local/bin/papply" works, also the one I prefer to use. thank you.
    – qinking126
    Dec 4, 2013 at 2:03
7

If you're on linux just do

unless => 'ls /somefile'

ls will return with a non-zero return code if the file does not exist and unless will only let the exec it is under execute if its test returns a non-zero return code.

2

On linux and puppet >3.8 try:

exec { 'test':
   command => '/bin/echo HI',
   unless  => 'test -f /a/file.txt',
}

exec will not run if /a/file.txt exists.

0

You might want to consider using creates, which exists for this purpose:

exec { 'git add url':
  command => 'git remote add origin https://github.com/testing/puppet.git',
  creates => '/usr/local/bin/papply'
}

You must log in to answer this question.

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