We've got a diverse dev team, one on Windows, another on Ubuntu and another on OSX. Being windows boy, I setup the first version of the vagrant setup script which works fabulously ;)
However, when running it on the Ubuntu host, the first time it gets to a provision step that calls a bash script, it fails due to permissions.
On windows, this doesn't matter as the samba share automatically has sufficient permissions to run the bash script (which resides within the project hierarchy, so is present in the /vagrant share on the VM), but with ubuntu I need to set the permissions on this file in the provision script before I call it.
This isn't the problem and to be honest I suspect even with the extra "chmod" step it would still work fine under windows, but, is there a way in the vagrant file to flag certain provisioning steps as 'Windows Only', 'Linux Only' or 'Mac Only'?
i.e. in pseduo code, something like.
. . if (host == windows) then config.vm.provision : shell, : inline => "/vagrant/provisioning/only_run_this_on_windows.sh" else if (host == linux) then config.vm.provision : shell, : inline => "/vagrant/provisioning/only_run_this_on_linux.sh" else if (host == osx) then config.vm.provision : shell, : inline => "/vagrant/provisioning/only_run_this_on_osx.sh" end if . .
Thanks in advance.
Command: vagrant provision [vm-name]Runs any configured provisioners against the running Vagrant managed machine. This command is a great way to quickly test any provisioners, and is especially useful for incremental development of shell scripts, Chef cookbooks, or Puppet modules.
By default, provisioners are only run once, during the first vagrant up since the last vagrant destroy , unless the --provision flag is set, as noted above.
Provisioners in Vagrant allow you to automatically install software, alter configurations, and more on the machine as part of the vagrant up process. This is useful since boxes typically are not built perfectly for your use case.
Note that Vagrant itself, in the Vagrant::Util::Platform class already implements a more advanced version of the platform checking logic in the answer by BernardoSilva.
So in a Vagrantfile, you can simply use the following:
if Vagrant::Util::Platform.windows? then myHomeDir = ENV["USERPROFILE"] else myHomeDir = "~" end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With