简体   繁体   English

Chef中ruby_block资源的奇怪行为

[英]Strange behavior with ruby_block resource in Chef

I have two ruby blocks at the end of a recipe: 我在食谱的结尾有两个红宝石块:

ruby_block 'set permissions for app dir' do
  block do
    require 'fileutils'
    FileUtils.chown_R 'user01', 'user01', '/mnt/app/'
  end
  action :run
end

ruby_block 'configure node app session' do
  block do
    cmd = "sudo su - user01 -c \"/mnt/app/http-app-/bin/app create /mnt/app/http-app/#{node['hostname']}\" && sudo su -c 'systemctl enable app' && sudo su -c 'systemctl start app'"
exec(cmd)
  end
  action :run
  not_if "stat -c %U /mnt/app/#{node['hostname']} |grep app"
end

A couple strange things are happening. 发生了一些奇怪的事情。 One, I cannot add any code after the last block... it will not run if added. 一个,我不能在最后一个块之后添加任何代码...如果添加,它将不会运行。 Two, when the cookbook runs the recipe never ends with if the run failed or was successful. 第二,当食谱运行时,如果运行失败或成功,则配方永远不会以结尾结束。 Bootstrapping the system a second time will prove to finish successful... but ssh'ing to the box and running chef-client comes back with an empty run list. 再次自举引导系统将证明已成功完成...但是,紧紧牵着箱子,正在运行的Chef-client会返回一个空的运行列表。

Can anyone explain this behavior? 谁能解释这种行为? How can i fix it? 我该如何解决?

exec() is not what you think. exec()不是您的想法。 That's a Ruby core method which calls the actual exec() syscall, which replaces the current process with something new. 这是一个Ruby核心方法,它调用实际的exec() syscall,用新的东西替换当前进程。 What you want is our shell_out!() helper which runs a subcommand and returns and object with the results. 您需要的是我们的shell_out!()帮助程序,它运行一个子命令并返回结果对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM