Use onlyif in EXEC

4,225 views
Skip to first unread message

Douglas Brancaglion

unread,
Mar 12, 2012, 3:23:57 PM3/12/12
to puppet...@googlegroups.com
Hi guys!

I need configure one command exec with onlyif parameter.

I want test file size exist or no.

Ho i do this?

Tks in advanced.

Douglas

Tim Sharpe

unread,
Mar 12, 2012, 4:45:04 PM3/12/12
to puppet...@googlegroups.com
Run command if file exists:
exec { 'foo'
  command => '<your command>',
  onlyif => '/usr/bin/test -f /file/that/must/exist/for/exec/to/run',
}

Run command unless file exists
exec {
  command => '<your command>',
  creates => '/path/to/file',
}
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Doug Chapman

unread,
Mar 12, 2012, 6:52:53 PM3/12/12
to puppet...@googlegroups.com
Checkout the 'creates' property, it seems like a cleaner way of doing this:


Douglas

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.




--
Doug Chapman


Douglas Brancaglion

unread,
Mar 13, 2012, 1:10:33 PM3/13/12
to puppet...@googlegroups.com
Tks guys!!

It's ok!




On 03/12/2012 07:52 PM, Doug Chapman wrote:
Checkout the 'creates' property, it seems like a cleaner way of doing this:
On Mon, Mar 12, 2012 at 12:23 PM, Douglas Brancaglion <douglas...@gmail.com> wrote:
Hi guys!

I need configure one command exec with onlyif parameter.

I want test file size exist or no.

Ho i do this?

Tks in advanced.


Douglas

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.




--
Doug Chapman


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.

Trammael

unread,
Mar 13, 2012, 4:26:36 PM3/13/12
to puppet...@googlegroups.com


On Monday, March 12, 2012 5:52:53 PM UTC-5, ed209 wrote:
Checkout the 'creates' property, it seems like a cleaner way of doing this:

Pardon the newbie question, but does work on or de-reference symlinks?

Cheers.

Mohamed Lrhazi

unread,
Mar 13, 2012, 4:51:04 PM3/13/12
to puppet...@googlegroups.com
You might want to rephrase your question, as it is not obvious, at
least not to me.

Mohamed.

> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.

> To view this discussion on the web visit
> https://groups.google.com/d/msg/puppet-users/-/uiuySO1RfNMJ.


>
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to

> puppet-users...@googlegroups.com.

Eugene Vilensky

unread,
Mar 14, 2012, 5:00:00 PM3/14/12
to puppet...@googlegroups.com
>> On Monday, March 12, 2012 5:52:53 PM UTC-5, ed209 wrote:
>>>
>>> Checkout the 'creates' property, it seems like a cleaner way of doing
>>> this:
>>>
>>> http://docs.puppetlabs.com/references/2.6.8/type.html#exec
>>
>>
>> Pardon the newbie question, but does work on or de-reference symlinks?
>>

On Tue, Mar 13, 2012 at 3:51 PM, Mohamed Lrhazi <lrh...@gmail.com> wrote:
> You might want to rephrase your question, as it is not obvious, at
> least not to me.
>
> Mohamed.

If the "creates" property of a Exec points to a symlink, what is the
effect if the target of the symlink is missing?

Cheers,

Peter Bukowinski

unread,
Mar 14, 2012, 5:20:08 PM3/14/12
to puppet...@googlegroups.com
The exec will not run in this case. The 'creates' attribute looks for something to exist at the specified path. A symlink, even if broken, is still a file.

These hypotheticals are simple to test out on your own. To test this case on any puppet client, first create a class:

#test.pp:
class test {
    exec { 'touch /opt/test.did.run': creates => '/opt/test.link' }
}

Then create a symlink to a non-existent file:

    ln -s /opt/nada /opt/test.link

Finally:

    puppet apply test.pp

/opt/test.did.run won't be created.

-- 
Peter M. Bukowinski
Sr. Systems Engineer
Janelia Farm Research Campus, HHMI

Peter Bukowinski

unread,
Mar 14, 2012, 5:40:52 PM3/14/12
to puppet...@googlegroups.com
Apologies, I was completely wrong. Must be something amiss with the above manifest. Even when the target is missing it wasn't running the exec. The following code will run the exec if the target is a broken symlink but will not run it if the target it a valid symlink:

puppet apply -e 'exec { "/bin/touch /opt/exec.did.run": creates => "/opt/test.link" }'

So, again, my former conclusion was incorrect. 'creates' appears to be smart enough to recognize a broken symlink as a missing file.

jcbollinger

unread,
Mar 15, 2012, 8:54:14 AM3/15/12
to Puppet Users
I don't call that "smart", I call it "buggy". The target of a symlink
is not the symlink itself. Even a broken symlink named in an Exec's
'creates' should be sufficient to prevent that Exec from running. At
best, the documentation is inadequate. I encourage you to file an
issue report.


John

Peter Bukowinski

unread,
Mar 15, 2012, 9:18:33 AM3/15/12
to puppet...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages