【问题标题】:How to delay entire chef recipe如何延迟整个厨师食谱
【发布时间】:2020-07-28 23:49:16
【问题描述】:

我是否可以延迟在 AWS OpsWorks 中运行的整个厨师食谱?

我试图执行睡眠命令但没有成功:

Chef::Log.info("Delaying chef execution")
execute 'delay' do
  command 'sleep 60'
end

我想要实现的是根据我进行延迟的位置来延迟配方中的所有 Ruby 代码,可能在顶部,也可能在中间。

编辑:完整的厨师食谱:

Chef::Log.info("stopping service rsyslog")
service 'rsyslog' do
  action :stop
end
Chef::Log.info("configuring private ip addresses for mesos_master templates")
ruby_block "configuring_mesos_master_templates" do
    # Do stuff
end
Chef::Log.info("starting service rsyslog")
service 'rsyslog' do
  action :start
end
Chef::Log.info("restarting service zookeeper")
service 'zookeeper' do
    action :restart
end
Chef::Log.info("restarting service mesos-master")
service 'mesos-master' do
    provider Chef::Provider::Service::Upstart
    action :restart
end
Chef::Log.info("starting service marathon")
service 'marathon' do
    action :start
end

【问题讨论】:

    标签: ruby shell chef-infra


    【解决方案1】:

    这样做很好,或者您可以使用ruby_block 资源和Ruby 的sleep() 方法。请记住排序的工作原理,请参阅 https://coderanger.net/two-pass/ 了解 compile-vs-converge 拆分的概述。

    【讨论】:

    • 实际上我写的代码不起作用,因为 OpsWorks 执行这个 Chef 配方,所有的东西都在同一时间运行。
    • 请记住,它只会在收敛时休眠,任何 ruby​​_block 之外的 Ruby 代码都将在编译时运行。如果您展示了一个更完整的示例,它可能会有所帮助。
    • 好的,你在哪里睡觉?我要记录一下,Chef 是围绕融合模型/意识形态构建的,而您拥有的配方基本上完全是程序步骤,并且更适合 bash 脚本。
    • 您也可能遇到与资源克隆相关的问题。
    • 我正试图睡在一切之上
    【解决方案2】:

    与此同时,Chef(15.5 版)为此引入了自己的“chef_sleep 资源”,如https://docs.chef.io/resources/chef_sleep/ 中所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 2021-11-01
      • 2014-12-05
      相关资源
      最近更新 更多