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

旧时模样 提交于 2019-12-06 02:26:05

问题


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

回答1:


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"




回答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.


来源:https://stackoverflow.com/questions/14182515/vagrant-how-to-print-chefs-command-output-to-stdout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!