hashicorp / vagrant

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

SMB Sync ignores smb_username and smb_password keys #11918

Open darkn3rd opened 4 years ago

darkn3rd commented 4 years ago

Please note that the Vagrant issue tracker is in priority reserved for bug reports and enhancements. For general usage questions, please use HashiCorp Discuss: https://discuss.hashicorp.com/c/vagrant/24 Thank you!

When submitting a bug report, please provide the minimal configuration and required information necessary to reliably reproduce the issue. It should include a basic Vagrantfile that only contains settings to reproduce the described behavior.

Tip: Before submitting your issue, don't hesitate to remove the above introductory text, possible empty sections (e.g. References), and this tip.

Vagrant version

Host operating system

This is the operating system that you run locally.

Guest operating system

Vagrantfile

hosts = File.readlines("./hosts").map { |ln| i,h= ln.split(/\s+/); [h,i] }.to_h
replicas = hosts.keys.select { |host| host.to_s.match /^zero-\d+/ }.count
version = ENV['DGRAPH_VERSION'] || 'v20.07.1'
smb_sync_opts = { type: "smb", mount_options: %w[mfsymlinks vers=3.0] }
smb_sync_opts.merge! smb_username: ENV['SMB_USER'] if ENV['SMB_USER']
smb_sync_opts.merge! smb_password: ENV['SMB_PASSWD'] if ENV['SMB_PASSWD']

Vagrant.configure("2") do |config|
  hosts.each do |hostname, ipaddr|
    config.vm.define hostname do |node|
      node.vm.box = "generic/ubuntu1804"
      node.vm.hostname = "#{hostname}"
      node.vm.network "private_network", ip: ipaddr

      if Vagrant::Util::Platform.windows_hyperv_enabled? then
        node.vm.synced_folder ".", "/vagrant", smb_sync_opts
      else
        node.vm.synced_folder ".", "/vagrant"
      end

      # node.vm.provision "shell" do |shell|
      #   shell.path = "provision.sh"
      #   shell.args = [replicas]
      #   shell.env = { DGRAPH_VERSION: version }
      #   shell.privileged = true
      # end
    end
  end
end

hosts (used for multi-machine)

192.168.123.21 zero-0
192.168.123.22 zero-1
192.168.123.23 zero-2
192.168.123.24 alpha-0
192.168.123.25 alpha-1
192.168.123.26 alpha-2

Debug output

Expected behavior

When supplying smb_username and smb_password, I expected that I would not be prompted. For 6 systems, I am prompted 6 times, so I wanted to lower the manual data entry using those keys in the 3rd param for config.vm.sync.

Actual behavior

The supplied smb_username and smb_password are ignored (described in https://www.vagrantup.com/docs/synced-folders/smb#options)

Steps to reproduce

$Env:VAGRANT_DEFAULT_PROVIDER = "hyperv"
$Env:SMB_USER = "$Env:USERNAME@$Env:COMPUTERNAME"
$Env:SMB_PASSWD = "<secret_password>"

vagrant up --no-provision

References

soapy1 commented 4 years ago

Looking into this a bit more, it looks like the issue here is with the Vagrant::Util::Platform.windows_hyperv_enabled? check. From the logs, it appears that an error is returned, resulting in return value of that function being false. So, I was able to get around this issue by removing that if statement.

darkn3rd commented 4 years ago

From what I can tell from the Get-WindowsOptionalFeature:

  1. This been an outstanding issue, but not fixed as other check(s) will discover that this running on Hyper-V (ref. https://github.com/hashicorp/vagrant/issues/10897)
  2. The problem with the command is that in PowerShell 3.0, DISM works with offline packages, so you have to add -Online option (ref. https://techibee.com/powershell/powershell-get-windowsoptionafeature-and-enable-windowsoptionalfeature-are-failing-solved/1795)

I ran two tests below and sure enough the -Online is required:

## FAILS
$(Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-Hypervisor).State
## SUCCEEDS
$(Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Hypervisor).State

Was this indeed blocking? Because from what I can tell from the logs and from my tests, and is that the SMB was working fine (logs), but either I was unnecessarily prompted, or what I passed was ignored. I'll double-check to make sure, put puts() debug statements.

darkn3rd commented 4 years ago

I tested the theory as well, with a simpler Vagrantfile and that routine is definitely not working. Is there a way to detect the current provider?

Vagrant.configure("2") do |config|
  config.vm.box = "generic/centos8"
  if Vagrant::Util::Platform.windows_hyperv_enabled? then
    puts "hyperv detected"
  else
    puts "hyperv not-detected"
  end
end
 vagrant up --provider hyperv
vagrant status
hyperv not-detected
Current machine states:
lyderX05 commented 4 years ago

Yes, it requires Online or Path option (For offline download location) but is it is also failing because hyperv function is looking of Get-WindowsFeature command it is only available if Server Manger is installed on that system which is always pre-installed in Windows Server but not home edition of Windows,

So check this PR for new update change 11933