vagrantpuppetvagrantfilesynced-folder

Vagrant and synced folders: How to set the owner to a user other than the default vagrant user?


I am trying to set up a development environment for a Rails 2 project within a CoreOS Vagrant VM that has a number of moving parts. Once the VM is provisioned there is a Puppet script that installs all the bits and pieces and starts them up.

The bit that I am working on, which is on my local machine (OS X 10.10.5), is exposed in to the VM via a synced folder and appears in the right place in the VM with owner vagrant and group vagrant.

In order for it to work with the rest of the system the owership of that folder needs to be set to projectx instead.

Simply telling Puppet to set the permissions doesn't work. They don't change. I've confirmed this by manually chowning the files and they don't change.

I can't just set the user in the Vagrantfile though as, until Puppet has done its stuff there is no projectx user.

It's looking like my only solution is to hack the Puppet files and eliminate the use of the projectx user but I'd rather find a way to set the owner of the synced folder instead as that would be much cleaner.

How do I set the ownership of a synced folder to a user that is not created until after the VM has been provisioned?


Solution

  • Unfortunately there are no easy ways to do that.

    Common workaround is to use uid and gid in sync folder configuration. This way you can create a synced folder as a user who will be added to the system later.

    projectx_uid = 1001
    projectx_gid = 1001
    config.vm.synced_folder "src/", "/srv/website",
      owner: projectx_uid, group: projectx_guid0
    

    This means projectx should be created at the very beginning of the provisioning process so it will have predictable uid/gid

    Related issue in Vagrant's tracker: https://github.com/mitchellh/vagrant/issues/936