Search code examples
vagrantvagrant-provision

Vagrant provision and not finding /vagrant?


I am trying to provision a VM, using Vagrant and virtual-box, for development and I am unable to access the /vagrant folder where I had expected my base configuration files to be, to copy to their locations.

BTW Host OS is MacOS X.

My directory structure is:

provision/
   install.sh
   config/
      nginx/mydomain
Vagrantfile

The contents of the Vagrantfile are as follows:

require 'yaml'
myproject_version = "0.22.1"

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "ubuntu/xenial64"

  config.vm.synced_folder ".", "/vagrant", create: true, group: "ubuntu", owner: "ubuntu"

  config.vm.provider :virtualbox do |vb, override|
    vb.name = 'myprojectserver-dev-standalone'

    # please customize hostname and private ip configuration if you needed.
    override.vm.hostname = "myhost"

    # frontend-webui
    override.vm.network :forwarded_port, guest: 5050, host: 5050
    # admin-webui
    override.vm.network :forwarded_port, guest: 8080, host: 8080
    # services
    override.vm.network :forwarded_port, guest: 8081, host: 8081

    override.vm.provision :shell do |s|
      s.path = "provision/install.sh"
      s.args = "/home/ubuntu ubuntu"
    end
  end

end

In my script I try:

ls -l /vagrant/
cp /vagrant/provision/config/nginx/mydomain

The problem is that the /vagrant directory doesn't exist. I tried creating it manually and then re-running the provision process, but no change.

Can anyone suggest what I may be doing wrong?


Solution

  • Turns out that while the box did come up, it would appear that the bootstrap did not fully complete due to configuration issues in the 'config.vm.provider' section. This meant that the vagrant mount never happened.

    On resolving those issues I then ran into a failure of the form:

    Failed to mount folders in Linux guest. This is usually because
    the "vboxsf" file system is not available. Please verify that
    the guest additions are properly installed in the guest and
    can work properly. The command attempted was:
    
    mount -t vboxsf -o uid=`id -u ubuntu`,gid=`getent group ubuntu | cut -d: -f3` vagrant /vagrant
    mount -t vboxsf -o uid=`id -u ubuntu`,gid=`id -g ubuntu` vagrant /vagrant
    

    Reading an issue report, the solution for this appeared to be to install the vagrant-vbguest plugin:

    vagrant plugin install vagrant-vbguest
    

    At this point I am able to complete provisioning.