Reuse provisioned nodes

I have a scenario where I setup node 1,2,3,4 in a loop. 1 use specific script and 2,3,4 other.
Now when initial sets of scripts on 1 is run and all from 2,3,4 arecompleted I want to be able to return to 1 reference and use more scripts on it, but only after 4 is done, is that possible I can’t find information about it.

Hey there,
one way to do this is to provision in 2 steps. For node 1, create a provisioner with run: "never" set. Then after the initial vagrant up, run the extra provisioner for for node 1 using vagrant provision --provision-with node_one_step_2. So, that can looks something like

Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.define :one do |c|
    c.vm.box = "hashicorp/bionic64"
    c.vm.provision "node_one", type: "shell", inline: "echo 'one: first'"
    c.vm.provision "node_one_step_2", type: "shell", run: "never", inline: "echo 'one: second'"
  end

  config.vm.define :two do |c|
    c.vm.box = "hashicorp/bionic64"
    c.vm.provision "node_2", type: "shell", inline: "echo 'two: first'"
  end

    ...
end

In the terminal:

$ vagrant up
$ vagrant provision --provision-with node_one_step_2
1 Like

Thank you! This looks very helpful I will try it out now.