Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant - how to print Chef's command output to stdout?

If we have in Chef cookbook code like:

if !File.exists?('/vagrant/project/target/project/WEB-INF") || node[:compile_project]
  bash "build project" do
    user "vagrant"
    cwd "/vagrant/project"
    code <<-EOH
      mvn clean
      mvn db-migration:migrate
      mvn package
    EOH
  end
end

When run vagrant up we can see only brief information that 'build project' is executed.

However wen we run 'mvn package' command from terminal we can see full command output. How to tell Vagrant/Chef to show full output?

EDIT:

I've tried this but nothing has changed in output.

config.vm.provision :chef_solo do |chef|
  chef.log_level = :debug
like image 230
Wojciech Bednarski Avatar asked Jan 06 '13 13:01

Wojciech Bednarski


2 Answers

I know nothing about vagrant but I think this may relate to your issue... Happy to delete this answer if proves to be irrelevant!

--force-formatter

Indicates that formatter output will be used instead of logger output.

So I found if solo.rb has log_location defined adding the option --force-formatter displays the output when running chef via rundeck or remotely executing ssh user@host "chef-solo --force-formatter"

like image 118
KCD Avatar answered Oct 20 '22 00:10

KCD


It prints bash/script/execute resource execution output to stdout only when:

  • You need TTY for your remote chef-solo/chef-client command.
  • not run chef-client in daemon mode
  • chef log level is set to :debug

See the code chef/Mixin/ShellOut, line 36.

When using vagrant up, it seems no option to provide a TTY for the ssh session, so the solution is kind of walk around after you set :debug log level for chef:

  1. run $ vagrant up
  2. run $ vagrant ssh -- -t - which means it passes -t to ssh command so that there's a tty for the ssh session.
  3. run chef-solo to manually run chef, then you will get output on stdout.
like image 2
shawnzhu Avatar answered Oct 20 '22 00:10

shawnzhu