厨师了解only_if执行资源

时间:2019-05-02 14:29:59

标签: ruby chef devops

我这里有一个看起来像这样的execute块

execute 'uninstall_datadog' do
  command 'sudo apt-get --purge remove datadog-agent -y'
  only_if 'command -v datadog-agent'
end

所以我的理解是,如果only_if的退出状态不是0,则此块将不会执行。这是真的吗?

2 个答案:

答案 0 :(得分:1)

是的。

但是我发现您的示例存在一些问题:

    内置<!DOCTYPE HTML> <html> <head> <script type="text/javascript"> window.onload = function () { var chart = new CanvasJS.Chart("chartContainer", { title:{ text: "RR Interval Time Series" }, data: [ { type: "line", dataPoints: [ <?PHP foreach($arr as $key => $v){ $output[] = "{ x: " . $x[$key] . ", y: " . $v . " }"; } echo implode(",\n", $output); ?> ] } ] }); var data = <?php echo json_encode($wshort, JSON_NUMERIC_CHECK); ?>; data = data.map(function (row, index) { return { x: index, y: row }; }); var chart2 = new CanvasJS.Chart("chartContainer2", { title: { text: "FFT Results" }, data: [{ type: "line", dataPoints: data }] }); var chart3 = new CanvasJS.Chart("chartContainer3", { title:{ text: "Poincare Plot" }, data: [ { type: "scatter", dataPoints: [ <?PHP foreach($pointy as $key1 => $v1){ $output1[] = "{ x: " . $pointx[$key1] . ", y: " . $v1 . " }"; } echo implode(",\n", $output1); ?> ] } ] }); chart.render(); chart2.render(); chart3.render(); } </script> <script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script></head> <body> <div id="chartContainer" style="height: 200px; width: 70%;"> </div> <div id="chartContainer2" style="height: 200px; width: 70%;"> </div> <div id="chartContainer3" style="height: 300px; width: 30%;"> </div> </body> </html> 资源可以删除软件包(如果已安装)。
package

如果尚未安装软件包,厨师将跳过它。  有关更多详细信息,请参见https://docs.chef.io/resource_package.html

  1. 通常Chef是root用户运行的,因此 package 'datadog-agent' do action :purge options '--yes' # not sure about this end 命令中不需要sudo命令。

  2. execute默认在chef-client / chef-solo / chef-apply进程的环境中运行。看到https://docs.chef.io/resource_common.html#arguments,您在模拟其他用户时必须调整only_if之类的环境变量

答案 1 :(得分:0)

command是一个内置的bash,看起来可能不是作为bash执行的。 bash -c "command -v datadog-agent"可以工作,但也可以改用which datadog-agent