At work, we use Vagrant on Windows 10 with the Hyper-V provider and, necessarily, SMB synced folders. It gets kind of annoying typing our entire corporate domain username and password every time we up a box... is there any way to set default SMB credentials?
It needs to work with Vagrantfiles checked into source control and cloned onto any developer machine.
Vagrant loads multiple Vagrantfiles from different locations. One of those being a user Vagrantfile.
~/.vagrant.d/Vagrantfile
https://www.vagrantup.com/docs/vagrantfile/#load-order-and-merging
But, the only username and _password like options, as of Vagrant 2.2.7, are provided directly on the synced_folder method.
https://www.vagrantup.com/docs/synced-folders/smb.html#options
Something you can do in the meantime is pull defualt username and domain info from environment vars...
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
default_smb_username = ENV['USERNAME']
default_smb_username = "#{ENV['USERNAME']}##{ENV['USERDNSDOMAIN'].downcase}" if ENV['USERDNSDOMAIN']
Vagrant.configure("2") do |config|
config.vm.synced_folder ".", "/vagrant"
config.vm.synced_folder ".", "/vagrant", smb_username: default_smb_username if default_smb_username
end
An issue has been opened asking for a solution.
https://github.com/hashicorp/vagrant/issues/11413
Related
On windows 10 I have ran my vagrant up and then ssh into my vm successfully. Installed apache2 php5-cli php5 libapache2-mod-php
Now when i access localhost:8080 it is showing me apache default welcome page. How can i access my site in the browser ?
Here are the contents of my Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 80, host: 8080
end
This is my current directory structure
You'll need to get your data into the VM and configure Apache to serve that data. For starters, add this to you Vagrantfile (after the confiv.vm.network line):
config.vm.synced_folder ".", "/var/www/html"
It will make your app folder available under /var/www/html on the VM. Apache on Ubuntu serves from that folder by default, so you should be able to see something after doing vagrant reload.
when you edit the configuration file by using vim or any other editor. After that, you have to reload the vagrant and then try to access the localhost:8080
Use the command
vagrant reload
Why I can't make new Virtual Machine using Vagrant, every time I do vagrant up it always overrides my previous created VM, even I changed the box name and vm name like below codes:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION_NO = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION_NO) do |config|
config.vm.define "vagrant" do |v|
v.vm.box = "changed_box_name"
........
v.vm.provider :virtualbox do |vb|
vb.gui = true
vb.name = "changed_vm_name"
.....
end
end
end
SOLVED
I got by deleting the .vagrant directory inside the main folder which Vagrant file is. The .vagrant directory holds the caches for every VM creation via vagrant up. In some of my environment that directory is AUTO clear every time I do vagrant up.
But not on my current unit (I'm not sure why) so I need to delete/remove (.vagrant) directory manually
Then changing box and vm name, eventually works to create new VM Instance.
Finally running vagrant up again.
I'm managing a few web services residing on different fixed hosts with ssh. I wanted to use vagrant so that I can edit local files and have them synced automagically.
however I'm having problems as I'm not using no provider or box, it's a fixed host and it feels like I'm going against vagramt's aim.
here's my Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.ssh.host = ...
config.ssh.username = ...
config.ssh.private_key_path = ".ssh/id_rsa"
config.vm.synced_folder "src/", "..."
config.vm.box = "myhost"
config.vm.provision :shell, :path => "bootstrap.sh"
end
and here's my bootstrap.sh file:
pip install flask sqlalchemy
but I can't make vagrant skip providing (with virtualbox or so)
well, as it always comes out - fighting against your tool in order to force it to do things it's not designed to are a bad idea.
there was probably a way to make vagrant use a void box but vagrant is too much for just keeping 2 directories synced. I found this nice tool that does exactly the same as vagrant for sync just without all the provider/provision etc.
I have been using Vagrant with VirtualBox for local development. Now, I want to deploy to Azure (question would be same with AWS).
When working locally with VirtualBox, it's awesome to have the synced folder. But I definitely don't want a synced folder for the cloud VM. So, how can I have it enabled for the former but disabled for the latter?
A snippet of my vagrantfile is below; however this doesn't seem to have any effect. Appreciate any pointers.
Vagrant.configure('2') do |config|
config.vm.synced_folder ".", "/vagrant"
# …
config.vm.provider :azure do |azure, override|
override.vm.synced_folder ".", "/vagrant", disabled: true
# …
End
# …
end
I've also tried initially disabling the synced folder, and then enabling it only for VirtualBox - but Azure still prompts for username/password and attempts to create an SMB share.
Update: Even if I disable it in the main section, and don't touch it for Azure, it still tries to create a SMB share, and complains that it can't find my machine (my laptop is behind NAT).
It turns out that the default synced folder was indeed being disabled correctly.
However, the Chef provisioner was being used, and behind the scenes this also uses synced folders! The solution therefore is to use a Chef server, or as I chose - to do everything via a shell provisioner.
Hope this question helps someone encountering this problem in the future.
I had the same problem with SMB synced folders not staying disabled even though I hade the correct lines to disable.
My problem was also caused by chef enabling synced folders again. I solved my problem by adding the chef.synced_folder_type = "rsync" to the chef config block:
config.vm.provision :chef_solo do |chef|
chef.synced_folder_type = "rsync"
[...more chef config...]
end
I am writing a cookbook which will be run on Ubuntu. It will create a directory in home of the default user.
directory "/home/<default-user>/my-directory" do
owner <default-user>
end
The problem is, this default user is different across environments:
It is vagrant when running on virtual machine using Vagrant.
And it is ubuntu when running on EC2 instance.
What is a good practice to solve this kind of problem? And how to do it?
Thank you!
Make the user an attribute and set that according to your environment.
directory "/home/#{node[:my_app][:default_user]}/my-directory" do
owner node[:my_app][:default_user]
end
Then, on your attributes/default.rb file:
default[:my_app][:default_user] = 'ubuntu'
and on your Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.provision "chef_solo" do |chef|
# ...
chef.json = {
"my_app" => {
"default_user" => "vagrant"
}
}
end
end
This will set your default user to ubuntu, but that will be overridden when running in the Vagrant VM.
Checkout the configuration entry config.ssh.username: http://docs-v1.vagrantup.com/v1/docs/config/ssh/username.html