1

My Vagrantfile creates three VMs: k8s-master, ndoe-1, and node-2. How can I enforce that k8s-master is fully provisioned before the provisioning for node-1 and nod-2 starts?

Here is my Vagrantfile:

IMAGE_NAME = "generic/ubuntu1804"
N = 2

Vagrant.configure("2") do |config|
  config.ssh.insert_key = false

  config.vm.provider "libvirt" do |v|
    v.memory = 1024
    v.cpus = 2
  end

  config.vm.define "k8s-master" do |master|
    master.vm.box = IMAGE_NAME
    master.vm.network "private_network", ip: "192.168.50.10"
    master.vm.hostname = "k8s-master"
    master.vm.provision "ansible" do |ansible|
      ansible.playbook = "kubernetes-setup/master-playbook.yml"
      ansible.extra_vars = {
        node_ip: "192.168.50.10",
      }
      ansible.compatibility_mode = "2.0"
    end
  end
  (1..N).each do |i|
    config.vm.define "node-#{i}" do |node|
      node.vm.box = IMAGE_NAME
      node.vm.network "private_network", ip: "192.168.50.#{i + 10}"
      node.vm.hostname = "node-#{i}"
      node.vm.provision "ansible" do |ansible|
        ansible.playbook = "kubernetes-setup/node-playbook.yml"
        ansible.extra_vars = {
          node_ip: "192.168.50.#{i + 10}",
        }
        ansible.compatibility_mode = "2.0"
      end
    end
  end
end

The multi-machine documentation mentions outside-in ordering, so I tried putting the for-each loop inside the k8s-master's define-block, but then the nodes are not created at all.

SergiyKolesnikov
  • 7,369
  • 2
  • 26
  • 47
  • You can most easily do this with `vagrant up k8s-master` followed by `vagrant up`, but that may not specifically be what you are looking for. – Matthew Schuchard May 13 '20 at 11:41
  • did you check https://stackoverflow.com/questions/34444506/vagrant-multi-machine-provisioning – Frederic Henri May 13 '20 at 13:13
  • @MattSchuchard Thanks! That is definitely a workaround. – SergiyKolesnikov May 13 '20 at 17:10
  • @FrédéricHenri Thanks for the pointer but the question there is how to run provisioning for all VMs after all of them were created. In my case, I have two different provisioning playbooks and want to run them in certain order. I do not really see how to apply that solution to my case. – SergiyKolesnikov May 13 '20 at 17:12

0 Answers0