0

I have the following line in my Vagrantfile:

config.vm.provision :shell, path: "provisioning/myscript.sh"

I would like to toggle running that script based on an environment variable being set in the host (which may not be present). If the value is present and equals true I want the script skipped, otherwise it should run e.g.

if [ ENV[SKIP_MY_SCRIPT] != 'true' ]
  config.vm.provision :shell, path: "provisioning/myscript.sh"
end

Or is there a better way (e.g. pass env into the script somehow)?

edwardmlyte
  • 15,937
  • 23
  • 58
  • 83

1 Answers1

0

As Vagrantfile is mainly a ruby script, there's no bad to have conditional statement in the file.

To answer the specific question How to pass host environment variable to provisioning script (can help for other use cases) you can pass arguments like

  username = `whoami`.chomp
  config.vm.provision "shell", privileged: false, path: "provisioning/config-git.sh", args: "#{username}"

and in your script, you read as

#!/usr/bin/env bash 
username=$1
Frederic Henri
  • 51,761
  • 10
  • 113
  • 139