How can I display the output of a Opscode Chef bash command in my console?

后端 未结 5 1702
傲寒
傲寒 2020-12-31 03:58

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.

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 04:36

    When you run chef - suppose we are using chef-solo, you can use -l debug to output more debug information into stdout.

    For example: chef-solo -c solo.rb -j node.json -l debug

    For example, a simple cookbook as below:

    $ 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
    

    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
    

    I think it contains the information you want. For example, output and the exit status of the shell script/command.

    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
    

提交回复
热议问题