Vagrant doesn't share my folders? - vagrant

I am using scotch box, for starters but consider the following:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.network "private_network", ip: "192.168.33.25"
config.vm.hostname = "scotchbox"
config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
# Optional NFS. Make sure to remove other synced_folder line too
# config.vm.synced_folder ".", "/var/www/", :nfs => { :mount_options => ["dmode=777","fmode=666"] }
config.vm.provider "virtualbox" do |v|
v.memory = 1536
end
end
Now consider the following folder:
Now consider the following after doing vagrant up && vagrant ssh then cd /var/www:
vagrant#scotchbox:/var/www$ ls
vagrant#scotchbox:/var/www$
Where is public/ and html/? I have tried the nfs method and still nothing. Ideas?

can you try to do :
config.vm.synced_folder "./", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
or use an absolute path.
One of the reason is that . is already mapped to /vagrant on the VM. You can check in the output of vagrant up the shared folder that are mapped. so depending how vagrant is doing with the order of synced folder it can map its vagrant folder so the . will be mapped with /vagrant and not the /var/www
If the existing /vagrant is the issue and you're not using you can add
config.vm.synced_folder ".", "/vagrant", disabled: true

Related

Vagrant Synced Folders not showing

I want to sync my OSX dev folder which contains my applications to my VM. My VagrantFile (based off Phansible):
Vagrant.require_version ">= 1.5"
Vagrant.configure("2") do |config|
config.vm.provider :virtualbox do |v|
v.name = "default"
v.customize [
"modifyvm", :id,
"--name", "default",
"--memory", 512,
"--natdnshostresolver1", "on",
"--cpus", 1,
]
end
config.vm.box = "ubuntu/trusty64"
config.vm.network :private_network, ip: "192.168.33.99"
config.ssh.forward_agent = true
if which('ansible-playbook')
config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible/playbook.yml"
ansible.inventory_path = "ansible/inventories/dev"
ansible.limit = 'all'
ansible.extra_vars = {
private_interface: "192.168.33.99",
hostname: "default"
}
end
else
config.vm.provision :shell, path: "ansible/windows.sh", args: ["default"]
end
config.vm.synced_folder "/Users/xylar/Code", "/vagrant", type: "nfs"
end
When I vagrant up:
==> default: Exporting NFS shared folders...
==> default: Preparing to edit /etc/exports. Administrator privileges will be required...
==> default: Mounting NFS shared folders...
==> default: Running provisioner: ansible...
There are no error messages and when I vagrant ssh and view contents of the vagrant folder I only see some dot files (ansible, bash etc). Is there something I have missed?
I was being foolish. Once I had ssh'd into the box I thought I was in the synced folder (as it was called vagrant) however I was in /home/vagrant and the synced location was in /vagrant.
You need to specify the mount options:
config.vm.synced_folder "/Users/xylar/Code", "/vagrant", "nfs" => { :mount_options => ['dmode=777', 'fmode=777'] }

Exported vagrant machine web directory empty, why is that?

I am trying to export a machine I created with vagrant to either an OVA file for Virtualbox or a package to host in vagrantcloud. The machine exports successfully, but then when I start it up, the directories which should have my files are empty. Seems like a vagrant noob question.
Why would "/usr/local/fieldpapers/" be empty when I start up my exported VM?
What can I do to keep files present in that directory after export?
Vagrant File:
# -*- 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.vm.synced_folder "./", "/usr/local/fieldpapers/", id: "vagrant-root",
owner: "vagrant",
group: "www-data",
mount_options: ["dmode=775,fmode=664"]
config.vm.provider :virtualbox do |vb, override|
vb.memory = 1024
vb.cpus = 1
vb.name = "Field Papers"
override.vm.box = "precise64"
override.vm.box_url = "http://files.vagrantup.com/precise64.box"
override.vm.network :private_network, ip: "192.168.33.10"
override.vm.provision :ansible, :playbook => "provisioning/playbook.yml"
end
end
First check your vagrant version, if it is latest.
Second, delete below line, vagrant will automatically mount your local folder to remote vagrant instance at /vagrant.
config.vm.synced_folder "./", "/usr/local/fieldpapers/", id: "vagrant-root",
owner: "vagrant",
group: "www-data",
mount_options: ["dmode=775,fmode=664"]

Vagrant + Chef + Hostname

I am pretty new using Vagrant and Chef. I am trying to change the Hostname of my Vagrant image using Chef. For some reason, I do not see a changed Hostname when I do vagrant ssh
What am I missing?
Here is my Cheffile
site "http://community.opscode.com/api/v1"
cookbook 'apt'
cookbook 'build-essential'
cookbook 'hostname'
Here is my Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Use Ubuntu 14.04 Trusty Tahr 64-bit as our operating system
config.vm.box = "ubuntu/trusty64"
# Configurate the virtual machine to use 2GB of RAM
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
# Forward the Rails server default port to the host
# config.vm.network :forwarded_port, guest: 3000, host: 3000
# Use Chef Solo to provision our virtual machine
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
chef.add_recipe "apt"
chef.add_recipe "hostname"
# Install Ruby 2.1.2 and Bundler
# Set an empty root password for MySQL to make things simple
chef.json = {
hostname: {
set_fqdn: 'Olympus'
}
}
end
end
As defined in the documentation you should set the attribute at the node level, not in node['hostname'].
In your case it will be
chef.json = {
set_fqdn: 'Olympus'
}
You can find more information in The hostname documentation

Vagrant overwrites host files during provision

I have been having an issue when vagrant overwrites the host files during when I run vagrnat provision.
In the src folder on my host machine (my laptop), I have a git repo with a .git folder and all the actual files that I use in the repo. When I run vagrant provision vagrant purges /var/www/site and because the folders are synced, destroy my host machine's copy of my site folder. Am I doing something wrong with folder syncing?
I'm running on Windows 7 with Vagrant 1.6.3 andVirtualbox 4.3.12
Vagrant.configure("2") do |config|
#Run a shell provisioner that installs the puppet-mongodb module
config.vm.provision "shell", path: "manifests/install_modules.sh"
# Enable the Puppet provisioner, with will look in manifests
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "default.pp"
puppet.module_path = "modules"
puppet.options = "--verbose --debug"
end
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise32"
# Forward guest port 80 to host port 8888 and name mapping
config.vm.network :forwarded_port, guest: 80, host: 8001
config.vm.network :forwarded_port, guest: 443, host: 8002
config.vm.synced_folder "site/", "/var/www/site", :owner => "www-data"
end
Whoops! I realized I had a line in my puppet config file that forced the var/www to be purged. This was actually a mistake in my puppet configs.
I changed this:
#Create the directory
file {["/var/www","/var/www/virt-env"]:
ensure => directory,
recurse => true,
purge => true,
force => true,
before => [
File["/var/www/virt-env/requirements.txt"],
Class['python']
],
}
To this:
#Create the directory
file{"/var/www":
ensure => directory
before => File["/var/www/virt-env/"]
}
file {"/var/www/virt-env":
ensure => directory,
recurse => true,
purge => true,
force => true,
before => [
File["/var/www/virt-env/requirements.txt"],
Class['python']
],
}

Vagrant complaints about "customize"

I'm having a weird problem with Vagrant. Changing the default RAM of the virtual machine would have to be easy but I don't know why I am not able to do it.
My code is very simple:
# -*- 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.vm.define "mimeticStack" do |v|
v.vm.box = "precise64"
v.vm.box_url = "http://files.vagrantup.com/precise64.box"
v.vm.network "private_network", ip: "192.168.33.10"
v.vm.network "forwarded_port", guest: 80, host: 8080
v.vm.hostname = "dev.mimetic.local"
v.vm.customize ["modifyvm", :id, "--memory", "512"]
end
end
Then if I run "vagrant up", Vagrant returns:
vm:
* The following settings shouldn't exist: customize
The issue was fixed:
# -*- 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.vm.define "mimeticStack" do |v|
v.vm.box = "precise64"
v.vm.box_url = "http://files.vagrantup.com/precise64.box"
v.vm.network "private_network", ip: "192.168.33.10"
v.vm.network "forwarded_port", guest: 80, host: 8080
v.vm.hostname = "dev.mimetic.local"
v.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id,'--memory', '512']
end
end
end
I left the code here for Vagrant beginners like me.
I have tried #MikeD's suggestion with
config.vm.provider "virtualbox" do |vb|
vb.memory = "<some size>"
vb.cpus = "<some number>"
end
and it works as expected. I can ssh into my vagrant box and run lscpu and cat /proc/meminfo which give me the values I specified above.

Resources