Search code examples
shellvagrantprovisioning

Will provisioning a second time re-run all the shell commands in my script?


I'm developing a Vagrant shell script to set up an Ubuntu VM with a whole bunch of things installed. I'm noticing that running sudo apt-get update during provisioning is taking a long time, and so testing that my Vagrant scripts are setting up the VM correctly is really slow.

If I run vagrant provision a second time, is it going to re-run all the shell commands in my script, or will it only re-run newly added setup stuff? I really want to reduce the development time for this script!


Solution

  • Use Bypass Logic in Your Provisioning Script

    When you re-run a given Vagrant shell provisioner, it must re-run the whole script. Any bypasses or short-circuiting you might want to apply must be designed into your script as conditional statements. As one example:

    # Only install something if a certain file is missing.
    if [ ! -f /some/file ]; then
        : # run your installer
    fi