hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.26k stars 4.43k forks source link

vagrant up - parameters to reduce outputs related to VM, Virtualbox & Vagrant #12791

Closed aphorise closed 1 year ago

aphorise commented 2 years ago

Provide additional parameters to disable and or reduce verbosity that's typically output as part of vagrant up and VM provisioning such as Network, Matching MAC address for NAT, Forwarding Port or SSH related events (before user scripts)

The intent with this request is to reduce verbosity for the purposes of presentations and drawing attention to pertinent user events or those that may be considered a warning or error in prior steps.

Outputs from a vagrant up run that's preferred as reducible to error only events and not always outputting - will be demonstrated below using double hashtag (##) to highlight the events in question:

Bringing machine 'v1' up with 'virtualbox' provider...
Bringing machine 'v2' up with 'virtualbox' provider...
==> v1: Importing base box 'debian/bullseye64'...
## ==> v1: Matching MAC address for NAT networking...
==> v1: Setting the name of the VM: v1-vault1_1655410655822_28993
## ==> v1: Clearing any previously set network interfaces...
## ==> v1: Preparing network interfaces based on configuration...
##     v1: Adapter 1: nat
##     v1: Adapter 2: bridged
##     v1: Adapter 3: bridged
## ==> v1: Forwarding ports...
##     v1: 22 (guest) => 2222 (host) (adapter 1)
==> v1: Running 'pre-boot' VM customizations...
==> v1: Booting VM...
==> v1: Waiting for machine to boot. This may take a few minutes...
##     v1: SSH address: 127.0.0.1:2222
##     v1: SSH username: vagrant
##     v1: SSH auth method: private key
##     v1:
##     v1: Vagrant insecure key detected. Vagrant will automatically replace
##     v1: this with a newly generated keypair for better security.
##     v1:
##     v1: Inserting generated public key within guest...
##     v1: Removing insecure key from the guest if it's present...
##     v1: Key inserted! Disconnecting and reconnecting using new SSH key...
==> v1: Machine booted and ready!
==> v1: Setting hostname...
==> v1: Configuring and enabling network interfaces...
==> v1: Mounting shared folders...
    v1: /vagrant => /Users/aphorise/git/hashicorp.vagrant_vault-dr
==> v1: Running provisioner: shell...
    v1: Running: ...
# // ... USER EVENTS FOLLOW ... 

Suggestion / Solution Perhaps in setting config.ssh provide parameter config.ssh.log_output that's configurable to ERROR|ALL|NONE and similarly the same with a setting in config.vm (eg: config.vm.log_output). Adjusting default (as per current behaviour in Vagrant 2.2.19) should allow for the above highlighted lines to only output in the event of issues rather than all the time with each new provision.

Alternatives considered Directing output 2>&1 which will not suffice as erroneous outputs as well as script related events should show. I also have config.vm.box_check_update = false in my current Vagrantfiles which help reduce outputs somewhat.

aphorise commented 1 year ago

A good work-around that's specific to versions: 2.x, prior to the yet to be released Vagrant 3.0 can be:

## Patch UI to hide detail messages
class Vagrant::UI::Colored
  def say(type, message, opts={})
    super(type, message, opts.merge(hide_detail: true))
  end
end

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/vagrant-share"
end

Messages could be conditionally evaluated and reduced as part of this over-ride approach which strips all non-bold outputs when setting hide_detail: true. The above approach is unlikely to work in Vagrant 3.0.

chrisroberts commented 1 year ago

Thank you for your feedback and recommendation, however, due to limited resources we are unable to prioritize this new work in our sprints. We are now closing this issue so that it is not stagnate.

The best way to get this implemented would be to submit a PR. If you want to discuss how to open a PR, I'd be happy to help with that.

Again, thank you for your suggestion. This is also an open source project we welcome contributions. Thanks!