只有在另一个Exec运行时才运行Exec

时间:2014-11-26 13:46:38

标签: puppet

如何将Exec配置为仅在另一个Exec运行时运行?

我有一个这样的清单:

file { $target:
    ensure => directory
}

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

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

我希望chown仅在unzip foobar.zip运行时运行。当然,我可以开始检查some-file-from-archive是否已归$user所有,但不知怎的,这似乎不对。

1 个答案:

答案 0 :(得分:3)

这里已有答案:http://ask.puppetlabs.com/question/14726/run-exec-only-if-another-exec-ran/

像这样更改清单修复了我的问题:

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,
}

更新28.11.2014

Felix Frank's comment推动我尝试了别的东西。而不是notify / refreshonly,您可以确保文件树中的所有资源都由用户拥有,如下所示:

exec { 'fix archive':
  command => "chown -R ${user} ${target}",
  path => '/bin',
  unless => "test 0 -eq $(find ${target} \\! -user ${user} | wc -l)"
}

这样,即使在$user运行后更改了所有者,也确保其为unpack file

相关问题