Ask Your Question

run Exec only if another Exec ran

asked 2014-11-26 00:31:42 -0600

yevmel gravatar image

hi there,

how can i configure a Exec to run only if another Exec ran?

i have a manifest like this:

file { $target:
    ensure => directory

exec { "unzip -C ${target}": 
    unless => "file ${target}/some-file-form-archive"

exec { "chown -R $user ${target}":
    onlyif => ???

i would like the chown to run only if unzip foobar ran. Of course i could start checking whether some-file-from-archive is already owned by $user, but somehow it does not seem right.

thx in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-11-26 07:52:33 -0600

llowder gravatar image

For placing the zip file and extracting it, you may want to take a look at the staging module.

But to answer the question as written,

In the first exec you'll want to use creates for that, rather than unless.

For the second exec, you'll want to use refreshonly.

This might look like:

exec { 'unpack file':
  command => "unzip -C ${target}",
  path        => '/usr/bin',
  creates    => "${target}/some-file-form-archive",
  require    => File[$target, '<archive>'],
  notify      => Exec[fix archive],

exec { 'fix archive':
  command => "chown -R ${user} ${target}",
  path => '/bin',
  refreshonly => true,

Note that I have not verified the paths are correct for where these commands are. You'll need to do that.

edit flag offensive delete link more


thx, works like a charm.... vagrant handles the "placing the zip file" for me, but thx for the hint anyway

yevmel gravatar imageyevmel ( 2014-11-26 08:50:02 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-11-26 00:31:17 -0600

Seen: 4,560 times

Last updated: Nov 26 '14