diff --git a/CHANGELOG.md b/CHANGELOG.md index 57a205154..f03144c38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ IMPROVEMENTS: - providers/virtualbox: Enable symlinks for VirtualBox 4.1. [GH-2414] - providers/virtualbox: default VM name now includes milliseconds with a random number to try to avoid conflicts in CI environments. [GH-2482] + - provisioners/shell: Added `keep_color` option to not automatically color + output based on stdout/stderr. [GH-2505] - synced\_folders/nfs: Specify `nfs_udp` to false to disable UDP based NFS folders. [GH-2304] diff --git a/plugins/provisioners/shell/provisioner.rb b/plugins/provisioners/shell/provisioner.rb index 1444ef18b..ab8579894 100644 --- a/plugins/provisioners/shell/provisioner.rb +++ b/plugins/provisioners/shell/provisioner.rb @@ -35,17 +35,13 @@ module VagrantPlugins # Output the data with the proper color based on the stream. color = type == :stdout ? :green : :red - # Note: Be sure to chomp the data to avoid the newlines that the - # Chef outputs. - if config.keep_color - @machine.env.ui.info( - data, - :new_line => false, :prefix => false) - else - @machine.env.ui.info( - data, - :color => color, :new_line => false, :prefix => false) - end + options = { + new_line: false, + prefix: false, + } + options[:color] = color if !config.keep_color + + @machine.env.ui.info(data, options) end end end diff --git a/website/docs/source/v2/provisioning/shell.html.md b/website/docs/source/v2/provisioning/shell.html.md index 03413b628..28edeb519 100644 --- a/website/docs/source/v2/provisioning/shell.html.md +++ b/website/docs/source/v2/provisioning/shell.html.md @@ -45,9 +45,10 @@ The remainder of the available options are optional: be uploaded to. The script is uploaded as the SSH user over SCP, so this location must be writable to that user. By default this is "/tmp/vagrant-shell" -* `keep_color` (boolean) - Vagrant automatically color output in green and - red (errors). If this is true, then Vagrant will not do this. By default - this is "false". This allow you to have custom colored output. +* `keep_color` (boolean) - Vagrant automatically colors output in green and + red depending on whether the output is from stdout or stderr. If this is + true, Vagrant will not do this, allowing the native colors from the script + to be outputted. ## Inline Scripts