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

2

5

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
Scum answered 6/1, 2013 at 13:17 Comment(2)
Okay, I think the answer is no. If the script works, the output stays hidden. However, one (extremely) hacky way to do this might be add attributes returns 2 and ignore_failure, which would fail every time. You get full output on failure. I would only use this technique to debug, however. And submit a feature request to opscode.Louden
Have you tried using the "flags" option for the bash resource to pass '-x' ?Arleyne
R
3

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"

Romance answered 29/11, 2013 at 3:49 Comment(1)
Thanks for the tip here, I managed to get vagrant to output the full chef run's output with chef.arguments = '--force-formatter' in the chef part of the Vagrantfile!Oilskin
T
2

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.
Translocation answered 19/10, 2013 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.