-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow setting default SMB credentials in my user Vagrantfile #11413
Comments
Oh, well, my janky workaround doesn't actually work... I guess the Vagrantfile merging method is more about building and merging Vagrant conf and less about like merging Ruby source files. So, that's even worse? I don't even have a bad workaround 😆 |
Hi @AnthonyMastrean - You should be able to potentially set these values as variables as you did, do you have a debug log of the result of running that Vagrantfile? |
Also please be aware that I think the smb password is usually your system password 🙈 Vagrant will typically scrub the logs with that, but always good to double check before sharing anything! Thanks. |
Also additionally, I should mention, since it seems like you are configuring the default share, you shouldn't actually need to do any of this. You should simply be able to put this line in your global Vagrantfile, and it should apply to all guests: ~/.vagrant.d/VagrantfileVagrant.configure("2") do |config|
config.vm.synced_folder ".", "/vagrant", smb_username: "username here", smb_password: "password here"
end
|
Variables inside the configure block scope didn’t seem to survive merging. Global variables outside the block scope seemed to work. You’re right about overriding the default synced folder in my user Vagrantfile. I think that’ll work in the short term. But, it will only work easily for the default synced folder. I don’t think I’m going to like adding every SMB synced folder I come across to my user Vagrantfile! And, actually wouldn’t synced folders in the folder/project scope override the same in the user scope? So, maybe I couldn’t use it that way. The other problem is, I really want to share these Vagrantfiles in source control with team members that may or may not end up setting up defaults. It would be nice if the default credentials solution is hidden from anyone not using it (unlike, adding globals to my user Vagrantfile and referencing them in the project Vagrantfile). |
To your last point, I imagine each of your team members probably have different smb_username and smb_passwords? Those values are your host system username and password, not the guest username and password that you're bringing up with Vagrant. So unless all of you have the same username and password, there isn't much value here in setting a default value to share in git if you're trying to get a usable default across multiple different machines for different people. Leaving them blank will just prompt your teammates for their host password. Which could be annoying, but at least it won't be a wrong default value. There isn't really a great way to set these values across a team, but mostly because of what they are. Each person should have a unique username and password, which makes it difficult to share. You could potentially abstract out these values and read them from a config file (like a json or yaml structure), and expect your team to fill out those values in the config file to prevent their Vagrantfile from adding unstaged changes or being wrong against the master branch with their local username/password. Then at least there won't be any extra changes to ignore with git, but the downside is now you have your system password in a json or yaml file in your project directory. |
@briancain I'm definitely talking about per-user host credentials. That's why I'm asking for per-user Vagrantfile configuration. I am, in fact, already checking into source control Vagrantfiles in several projects. And I'm defining more synced folder than just the default. I was trying to keep the convo generic, but we were getting a little lost without details. 🤗 I feel like it's a reasonable "feature request" and in line with some of your other configuration options (whether per-user Vagrantfile conf or user-scoped env vars). |
@AnthonyMastrean I guess I'm not 100% clear as to what the feature request is... you should be able to define these defaults like: ~/.vagrant.d/VagrantfileDEFAULT_SMB_USERNAME="username"
DEFAULT_SMB_PASSWORD="password"
Vagrant.configure("2") do |config|
# setting this synced folder is not required, btw. The variables above
# will be accessible anywhere as long as it gets loaded by Vagrant
config.vm.synced_folder ".", "/vagrant", smb_username: DEFAULT_SMB_USERNAME,
smb_password: DEFAULT_SMB_PASSWORD
end Or those could also exist in your local Vagrantfile in your project directory too. That seems like it should cover the use case you are looking for, or am I missing something? 🤔 |
An easy solution to this is to reference environment variables for the values within the configuration. Then users can opt-in to setting them if they like, and if they don't they will be prompted by Vagrant when setting up the synced directories: Vagrant.configure("2") do |config|
config.vm.synced_folder '.', '/vagrant', smb_username: ENV["SMB_USERNAME"], smb_password: ENV["SMB_PASSWORD"]
end Cheers! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Vagrant version
Vagrant 2.2.7
Host operating system
Windows 10
Guest operating system
Any
Vagrantfile
Debug output
Expected behavior
I should be able to setup default SMB credentials for any subsequent SMB synced folder in my user Vagrantfile.
That's this one, per the docs:
https://www.vagrantup.com/docs/vagrantfile/#load-order-and-merging
Actual behavior
Since the
smb_username
andsmb_password
andmount_options
are method parameters onsynced_folder
, I cannot easily set defaults in a way that still allows me to share this Vagrantfile with coworkers.I have to do something janky like...
~/.vagrant.d/Vagrantfile
And then in my ultimate Vagrantfile
Steps to reproduce
References
The text was updated successfully, but these errors were encountered: