Ask Your Question
0

run Exec only if another Exec ran

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

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 foobar.zip -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
1

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

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 foobar.zip -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

Comments

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 -0500 )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

Stats

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

Seen: 3,515 times

Last updated: Nov 26 '14