Run a block pre :synced_folder run

Using the trigger methods.

Why is it still not possible for the following to work.

trigger.before :synced_folder do |trigger| = “SOMETHING PRE mount, like add a user to guest”

expected behavour
run block above in trigger before synced_folder actions.

actual happens

if the :sync_folders is changed to :up, then it runs the block pre up.

we need a way of poking commands pre mount.

this is to allow flexiable control of mount owner /group options.

Workaround is to hardcode an id number!

create a section for guest inline shell pre mount

Hey there,
:synced_folder is not an available action to trigger on (check out the list of available ones Vagrant Triggers Configuration | Vagrant by HashiCorp).

However, you can probably use typed triggers to achieve your goal of running something before folders get synced.
In order to use this feature, you’ll need to enable the experimental feature flag:


Then you can make a trigger on the sync folder action. Something like:

config.trigger.before :"Vagrant::Action::Builtin::SyncedFolders", type: :action do |t| = "Before action class!

Many thanks, I will give that a shot. I was hoping to get the trigger to actually do something of use, which I think is missing. add a user so that the given owner of a share is created if not found. the current process of syncedfolders is to fail if the owner dont exist,( which I would consider a bit poor) it would be better if it actually created the user for the owner

      t.trigger.before :"Vagrant::Action::Builtin::SyncedFolders", type: :action do |t|
  = "Before action class!"
           t.warn = "add user"
           #t.run_remote ={inline:"uname -n"}

The above trigger worked but it ran to early! is it possible to next these triggers, so it runs
==> ansible: Before action class!
==> ansible: add user far to early to be of use
==> ansible: Clearing any previously set network interfaces…
==> ansible: Preparing network interfaces based on configuration…
ansible: Adapter 1: nat
ansible: Adapter 2: hostonly
==> ansible: Forwarding ports…
ansible: 22 (guest) => 2205 (host) (adapter 1)
==> ansible: Running ‘pre-boot’ VM customizations…
==> ansible: Booting VM…
==> ansible: Waiting for machine to boot. This may take a few minutes…
ansible: SSH address:
ansible: SSH username: vagrant
ansible: SSH auth method: private key
==> ansible: Machine booted and ready!
==> ansible: Checking for guest additions in VM…
==> ansible: Setting hostname…
HERE, so is it possible to trigger after setting hostname but before sharefolders.

==> ansible: Configuring and enabling network interfaces…
==> ansible: Mounting shared folders…

This is to inject the user of the share owner into the guest vm, there has to be an easier way to do that

Right, apologies about Vagrant::Action::Builtin::SyncedFolders, looks like that’s the wrong action to attach to. You can see a list of the all the action available to a provider by inspection (it might be cool one day if there was some more digestible docs for this). For example, the actions available to virtualbox are listed here: vagrant/plugins/providers/virtualbox/action at main · hashicorp/vagrant · GitHub.
It looks like a trigger on the action VagrantPlugins::ProviderVirtualBox::Action::Boot will to what you are looking for.