hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.02k stars 4.42k forks source link

Vagrantfile's provisioners dependency is working with 2.3.7 but not with 2.4.0 #13283

Open oz123 opened 8 months ago

oz123 commented 8 months ago

Debug output

With vagrant version 2.4.0 downloaded from https://releases.hashicorp.com/vagrant/2.4.0/vagrant_2.4.0_linux_amd64.zip

$ vagrant up
There are errors in the configuration of this machine. Please fix
the following errors and try again:

provisioner:
* Could not find provisioner name `subscribevm2` defined for machine `vm2` to run provisioner "start-app" `after`.
* Could not find provisioner name `subscribevm2` defined for machine `vm2` to run provisioner "subscribevm1" `after`.

Expected behavior

The file actually works the same as with Vagrant 2.3.7. See gist containing the file:

Actual behavior

The doesn't work with

Host operating system

Ubuntu Jammy.

Guest operating system

Ubuntu Focal.

Steps to reproduce

  1. Vagrant up
  2. Fail.
  3. Downgrade vagrant to 2.3.7
  4. It works.

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.provision "install-pg", run: "once", type: "shell", path: "./scripts/install-pg-16.sh"
  config.vm.provision "clean-pg", run: "never", type: "shell", path: "./scripts/clean-postgresql.sh"
  config.vm.provision "prep-pg", run: "once", type: "shell", path: "./scripts/prepare-postgresql.sh"
  config.vm.provision "copy-config", type: "file", source: "./config/config.yaml", destination: "/tmp/config.yaml"

  ["vm1", "vm2"].each do |machine|
    config.vm.define machine do |machine_config|
      machine_config.vm.box = "generic/ubuntu2004"
      machine_config.vm.hostname = machine

      if machine == "vm1"
        machine_config.vm.network "private_network", ip: "192.168.121.121"
      elsif machine == "vm2"
        machine_config.vm.network "private_network", ip: "192.168.121.122"
      end

      machine_config.vm.provider "virtualbox" do |v|
        v.name = machine
        v.memory = 1024*4
        v.cpus = 2
      end

      machine_config.vm.provider "libvirt" do |v|
        v.memory = 1024*4
        v.cpus = 2
      end
      machine_config.vm.synced_folder "./", "/vagrant", type: "nfs", nfs_udp: false, mount_options: ["nolock"]
      if machine == "vm1"
        machine_config.vm.provision :publishvm1, type: "shell", path: "./scripts/publish-postgresql.sh"
        machine_config.vm.provision :subscribevm2, after: "publishvm2", run: "once", type: "shell", path: "./scripts/subscribe-postgresql-node.sh"
      elsif machine == "vm2"
        machine_config.vm.provision :publishvm2, type: "shell", path: "./scripts/publish-postgresql.sh"
        machine_config.vm.provision :subscribevm1, after: "publishvm1", run: "once", type:"shell", path: "./scripts/subscribe-postgresql-node.sh"
      end
    end
  end
  config.vm.provision "start-app", run: "always", after: "subscribevm2", type: "shell", path: "./scripts/start-app.sh"
end