ReynierPM
ReynierPM

Reputation: 18660

Can I force provisioning to happen before mounting shared folders in Vagrant?

I have the following Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "centos/6"
  config.vm.provision :shell, :path => "bootstrap.sh"
  config.vm.network :forwarded_port, host: 8080, guest: 80
  config.vm.network :forwarded_port, host: 3306, guest: 3306
  config.vm.synced_folder "../../applications", "/var/www/html", :owner=>"apache", :group=>"apache"

  config.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--memory", 2048]
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
      vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
      vb.name = "appserver"
   end
end

Each time I run vagrant up (for first time, let's say that first I ran vagrant destroy -f) I end up with the following error:

==> default: Mounting shared folders...
    default: /vagrant => E:/Development/vagrant/centos6
    default: /var/www/html => E:/Development/applications/arx
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

id -u apache    
The error output from the command was:    
id: apache: No such user

The error is pretty clear "apache user does not exists". As I am seeing this there is two or "three" ways to fix this:

Does any know if this is possible and if so how? I wasn't able to found anything regarding the 3rd solution :( if you have a better solution you're more than welcome to post here it might help me and others probably.

I have found this and this but is not helpful.

Upvotes: 3

Views: 807

Answers (2)

Tns
Tns

Reputation: 410

You can use numeric ids and then create an user

config.vm.synced_folder '${HOSTDIR}', '${EXPORTDIR}', type: "virtualbox", owner: '123', group: '456'
config.vm.provision :shell, inline: "useradd --system -g '456' -u '123' -d '${EXPORTDIR}' --shell /bin/false apache"

Upvotes: 0

Frederic Henri
Frederic Henri

Reputation: 53713

one potential solution would be to run apache as vagrant user.

In your /etc/httpd/conf you can replace the User and Group value as

User vagrant
Group vagrant

so you can continue sharing your folder with vagrant user and httpd will be run as vagrant user.

Upvotes: 2

Related Questions