如何在控制台中显示Opscode Chef bash命令的输出?

我使用Vagrant生成一个标准的“精准32”框,并配置了厨师,所以我可以在Windows上测试我的Node.js代码在Linux上.这工作正常

我也有这个bash命令,所以它自动安装我的npm模块:

bash "install npm modules" do
  code <<-EOH
    su -l vagrant -c "cd /vagrant && npm install"
  EOH
end

这也可以正常工作,除非我没有看到控制台输出,如果它成功完成.但是我想看到它,所以我们可以直观地监视发生了什么.这不是特定于npm.

我看到这个类似的问题,没有具体的答案:Vagrant – how to print Chef’s command output to stdout?

我尝试指定标志,但我是一个可怕的linux / ruby​​ n00b,并创建任何错误或没有输出,所以请编辑我的代码段与您的解决方案的示例.

最佳答案
当你运行厨师时 – 假设我们使用厨师独奏,可以使用-l debug将更多的调试信息输出到stdout.

例如:chef-solo -c solo.rb -j node.json -l debug

例如,一本简单的食谱如下:

$tree 
.
├── cookbooks
│   └── main
│       └── recipes
│           └── default.rb
├── node.json
└── solo.rb

3 directories, 3 files

default.rb

bash "echo something" do
   code <<-EOF
     echo 'I am a chef!'
   EOF
end

您会看到如下输出:

Compiling Cookbooks...
[2013-07-24T15:49:26+10:00] DEBUG: Cookbooks to compile: [:main]
[2013-07-24T15:49:26+10:00] DEBUG: Loading Recipe main via include_recipe
[2013-07-24T15:49:26+10:00] DEBUG: Found recipe default in cookbook main
[2013-07-24T15:49:26+10:00] DEBUG: Loading from cookbook_path: /data/DevOps/chef/cookbooks
Converging 1 resources
[2013-07-24T15:49:26+10:00] DEBUG: Converging node optiplex790
Recipe: main::default
  * bash[echo something] action run[2013-07-24T15:49:26+10:00] INFO: Processing bash[echo something] action run (main::default line 4)
[2013-07-24T15:49:26+10:00] DEBUG: Platform ubuntu version 13.04 found
I am a chef!
[2013-07-24T15:49:26+10:00] INFO: bash[echo something] ran successfully

    - execute "bash"  "/tmp/chef-script20130724-17175-tgkhkz"

[2013-07-24T15:49:26+10:00] INFO: Chef Run complete in 0.041678909 seconds
[2013-07-24T15:49:26+10:00] INFO: Running report handlers
[2013-07-24T15:49:26+10:00] INFO: Report handlers complete
Chef Client finished, 1 resources updated
[2013-07-24T15:49:26+10:00] DEBUG: Forked child successfully reaped (pid: 17175)
[2013-07-24T15:49:26+10:00] DEBUG: Exiting

我想它包含你想要的信息.例如,输出和shell脚本/命令的退出状态.

BTW:看起来有一个限制(提示输入密码?),你将无法使用su

[2013-07-24T15:46:10+10:00] INFO: Running queued delayed notifications before re-raising exception
[2013-07-24T15:46:10+10:00] DEBUG: Re-raising exception: Mixlib::ShellOut::ShellCommandFailed - bash[echo something] (main::default line 4) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20130724-16938-1jhil9v" ----
STDOUT: 
STDERR: su: must be run from a terminal
---- End output of "bash"  "/tmp/chef-script20130724-16938-1jhil9v" ----
Ran "bash"  "/tmp/chef-script20130724-16938-1jhil9v" returned 1

转载注明原文:如何在控制台中显示Opscode Chef bash命令的输出? - 代码日志