Override the PATH variable in the Vagrantfile before syncing folders

29 views
Skip to first unread message

Victor Fernandez

unread,
Jun 1, 2019, 6:52:52 AM6/1/19
to Vagrant
Hi all,

I'm using Vagrant 2.2.4 with VirtualBox 6.0.8 on macOS Mojave 10.14.5.

I'm running into trouble with a NetBSD 8 box while setting up the shared folder.

This is my Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "NetBSD/NetBSD-8.0"
  config.vm.box_version = "1.0.0"

  PATH = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin"
  
  config.vm.synced_folder ".", "/vagrant", type: "rsync", group: "users" rsync__chown: false
  config.ssh.shell = "sh"

  config.vm.provision "shell", inline: <<-SHELL

    PATH=$PATH:/sbin:/usr/sbin:/usr/pkg/sbin
    export PATH

    PKG_PATH=ftp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/8.0/All
    export PKG_PATH
    pkg_add gmake
  SHELL
end

When I start the machine (vagrant up), I get this error:

==> default: Rsyncing folder: /Users/vikman/Projects/Vagrant/NetBSD/ => /vagrant
There was an error while attempting to run the post rsync
command for a synced folder. Please inspect the error message
below for more info.

Host path: /Users/vikman/Projects/Vagrant/NetBSD/
Guest path: /vagrant
Error: The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

find /vagrant '!' -type l -a '(' ! -user vagrant -or ! -group users ')' -exec chown vagrant:users '{}' +

Stdout from the command:



Stderr from the command:

find: chown: No such file or directory

I found that the current PATH was:

/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin

In fact, chown is at /sbin.

However, when I get into the machine (vagrant ssh), I get this value of PATH:

/home/vagrant/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R7/bin:/usr/pkg/bin:/usr/pkg/sbin:/usr/games:/usr/local/bin:/usr/local/sbin

I found this workaround: disable rsync_chown and run the command that failed in the provision script.

Vagrant.configure("2") do |config|
  config.vm.box = "NetBSD/NetBSD-8.0"
  config.vm.box_version = "1.0.0"

  config.vm.synced_folder ".", "/vagrant", type: "rsync", group: "users" rsync__chown: false
  config.ssh.shell = "sh"

  config.vm.provision "shell", inline: <<-SHELL
    PATH=$PATH:/sbin:/usr/sbin:/usr/pkg/sbin
    export PATH

    find /vagrant '!' -type l -a '(' ! -user vagrant -or ! -group users ')' -exec chown vagrant:users '{}' +

    PKG_PATH=ftp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/8.0/All
    export PKG_PATH
    pkg_add gmake
  SHELL
end

My question is: can I override the PATH variable prior to setting up the synced folder, or can I fix this issue in another way?

Thank you in advance!

Cheers,

Victor
Reply all
Reply to author
Forward
0 new messages