我怎样才能显示OPS code厨师bash命令在我的控制台输出?
我用流浪产卵一个标准的precise32框,并提供其与厨师,所以我可以测试在Linux上我的Node.js code,当我在Windows机器上运行。这工作得很好。
I use Vagrant to spawn a standard "precise32" box and provision it with Chef so I can test my Node.js code on Linux when I work on a Windows machine. This works fine.
我也有这个bash命令所以它自动安装我的新公共管理模块:
I also have this bash command so it auto installs my npm modules:
bash "install npm modules" do
code <<-EOH
su -l vagrant -c "cd /vagrant && npm install"
EOH
end
这同样适用,只是我从来没有看到控制台输出,如果它成功完成罚款。但我想看到它,所以我们可以直观地监视是怎么回事。这不是特定于NPM。
This also works fine except that I never see the console output if it completes successfully. But I'd like to see it so we can visually monitor what is going on. This is not specific to npm.
我看到没有具体的答案,这类似的问题:Vagrant - 如何打印厨师的命令输出到stdout
I see this similar question with no concrete answers: Vagrant - how to print Chef's command output to stdout?
我试过指定标志,但我是一个可怕的Linux /红宝石的n00b,并在所有创建错误或无输出,所以请您的解决方案的例子编辑我的片段。
I tried specifying flags but I'm a terrible linux/ruby n00b and create either errors or no output at all, so please edit my snippet with an example of your solution.
当您运行的厨师 - 假设我们使用厨师独奏
,您可以用 -l调试
输出更多的调试信息到标准输出。
When you run chef - suppose we are using chef-solo
, you can use -l debug
to output more debug information into stdout.
例如:厨师独奏-c solo.rb -j node.json -l调试
例如,一个简单的食谱,如下:
For example, a simple cookbook as below:
$ tree
.
├── cookbooks
│ └── main
│ └── recipes
│ └── default.rb
├── node.json
└── solo.rb
3 directories, 3 files
default.rb
default.rb
bash "echo something" do
code <<-EOF
echo 'I am a chef!'
EOF
end
您会看到下面的输出象下面这样:
You'll see the following output like below:
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脚本/命令的退出状态。
I think it contains the information you want. For example, output and the exit status of the shell script/command.
BTW:看起来像有(密码提示?)的限制,你将无法使用苏
BTW: looks like there is a limitation (prompt for password?), you won't be able to use 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