Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude (ignore) certain folders in vagrant rsync?

Tags:

vagrant

rsync

I wish to run npm install in my vagrant virtual box.

But whenever I ran the npm install command, my rsync will execute. Since my host computer does not have node_modules installed, it simply remove the folder completely for me.

What do I need to do so that my vagrant rsync will ignore the node_modules folder?

I cannot have node_modules being rsynced into the guest machine because my host and guest are two different systems. So far my vagrantfile looks like this.

Vagrant.configure("2") do |config|
  config.vm.box = "laravel/homestead"

  config.vm.hostname = "localhost"

  config.vm.network "forwarded_port", guest: 8000, host: 8000

  config.vm.synced_folder "./", "/home/vagrant/app"

  config.vm.provider "virtualbox" do |v|
    v.name = "web2"
    v.memory = "4096"
    v.cpus = 2
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME", "1"]
  end

  config.vm.synced_folder "./", "/home/vagrant/app", type: "rsync", rsync_auto: true, rsync_exclude: ['node_modules*']
  config.vm.provision :shell, path: "provision/setup.sh"

end

And I execute vagrant rsync via

vagrant rsync-auto
like image 484
Zhen Liu Avatar asked Dec 18 '22 07:12

Zhen Liu


1 Answers

rsync__exclude as well as rsync__auto takes 2 _

You need to rewrite your line as

config.vm.synced_folder "./", "/home/vagrant/app", type: "rsync", rsync__auto: true, rsync__exclude: ['./node_modules*']
like image 85
Frederic Henri Avatar answered Jan 23 '23 17:01

Frederic Henri