Search code examples
vagrantvagrantfile

Vagrant shell provisioner repeats five times


The shell provisioner is running five times, and I cannot find why this is happening. My Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "papasmurf/win2016base"
  config.vm.communicator = "winrm"
  config.winrm.username = "vagrant"
  config.winrm.password = "vagrant"
  config.winrm.timeout = 180
  config.vm.guest = :windows
  config.windows.halt_timeout = 15

  config.vm.provider "virtualbox" do |vb|
    vb.linked_clone = true
    vb.name = "DBSRV2016"
    vb.memory = "4096"
    vb.gui = false
    vb.cpus = 2

    config.vm.provision "shell" do |s|
      s.privileged = "true"
      s.inline = "echo Hello World"
    end
  end
end

The inline command was a cmd file first, but while I was investigating this issue I found that even the echo Hello World is executed five times.

This is the debug log: https://www.dropbox.com/s/syl8f50xldu32xr/vagrant.log?dl=1

Any idea what is wrong here?


Solution

  • Move provision block outside provider:

    Vagrant.configure("2") do |config|
      config.vm.box = "papasmurf/win2016base"
      config.vm.communicator = "winrm"
      config.winrm.username = "vagrant"
      config.winrm.password = "vagrant"
      config.winrm.timeout = 180
      config.vm.guest = :windows
      config.windows.halt_timeout = 15
    
      config.vm.provider "virtualbox" do |vb|
        vb.linked_clone = true
        vb.name = "DBSRV2016"
        vb.memory = "4096"
        vb.gui = false
        vb.cpus = 2
      end
    
      config.vm.provision "shell" do |s|
        s.privileged = "true"
        s.inline = "echo Hello World"
      end
    end