Vagrant chicken-and-egg: Shared folder with uid = apache user

Alex picture Alex · Jul 31, 2013 · Viewed 8.9k times · Source

My Vagrant box is build from a base linux (scientific linux), during provisioning (using shell scripts), Apache is installed.

I recently changed the Vagrant file (v2) to:

config.vm.synced_folder "public", "/var/www/sites.d/example.com",
   :owner => "apache", :group => "apache"

Which works well if the box is already provisioned and just rebooted.

Now, after a vagrant destroy && vagrant up I get the error:

mount -t vboxsf -o uid=`id -u apache`,gid=`id -g apache` 
   /var/www/sites.d/example.com /var/www/sites.d/example.com
id: apache: User does not exist

Which is clear - as during the initial run, apache is not yet installed.

An ugly workaround would of course be to do the basic provisioning with that synced_folder commented out, comment it in and then reboot.

Is there any clean trick to solve that? Especially in a way that vagrant up always runs without interruptions, even if the box is new.

Answer

Sean Burlington picture Sean Burlington · Oct 30, 2013

If you can fix the uid/gid values you can use these in the mount command - they don't have to relate to an existing user/group

I do this with a user that is later created by puppet using fixed (matching)uid / gid values

config.vm.synced_folder "foo", "/var/www/foo",
   id: "foo", :mount_options => ["uid=510,gid=510"]