title: Vagrant multiple vm with separate provisioning scripts
body: <p>Currently trying to set up multiple VMs, with separate provisioning scripts.</p>
  
  <p>Vagrantfile is as follows;</p>
  
  <pre><code>dir = Dir.pwd
  vagrant_dir = File.expand_path(File.dirname(__FILE__))
  
  VAGRANTFILE_API_VERSION = "2"
  
  Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  
      box_name = "puppetlabs/centos-6.5-64-puppet"
  
      # our web/app servers and their IPs - format 192.168.1.8##
      app_servers = {
  
          'web11' =&gt; {
              :name =&gt; 'web11',
              :ip =&gt; '192.168.1.811',
              :box =&gt; box_name,
              :forwarded_port_guest =&gt; 811,
              :forwarded_port_host =&gt; 8811
          },
  
          'web21' =&gt; {
              :name =&gt; 'web21',
              :ip =&gt; '192.168.1.821',
              :box =&gt; box_name,
              :forwarded_port_guest =&gt; 821,
              :forwarded_port_host =&gt; 8821
          },
  
          'learninglocker' =&gt; {
              :name =&gt; 'learninglocker',
              :ip =&gt; '192.168.1.899',
              :box =&gt; box_name,
              :forwarded_port_guest =&gt; 899,
              :forwarded_port_host =&gt; 8899
          }
  
      }
  
      app_servers.each do |key,value|
  
          boxname = value[:name]
  
          config.vm.define boxname do |app_config|
  
              app_config.vm.provision "shell", inline: "echo !!!thisname!!!! #{key}"
              app_config.vm.provision "shell", inline: "echo !!!thisip!!!! #{value[:ip]}"
  
              app_config.vm.box = value[:box]
              app_config.vm.host_name = "%s.vagrant" % value[:name]
  
              app_config.vm.network "private_network", ip: value[:ip]
              app_config.vm.network "forwarded_port", guest: value[:forwarded_port_guest], host: value[:forwarded_port_host]
  
              app_config.ssh.forward_agent = true
  
              provision_filename = key.to_s + "-provision.sh"
              config.vm.provision "shell", inline: "echo #{provision_filename}"
  
              # provisioning
              if File.exists?(File.join(vagrant_dir,'provision',boxname + "-provision.sh")) then
                  config.vm.provision "shell", inline: "echo +++exists+++"
                  config.vm.provision :shell, :path =&gt; File.join( "provision", boxname + "-provision.sh" )
              else
                  config.vm.provision "shell", inline: "echo PROVISION FILE DOES NOT EXIST!"
              end
  
              # Shared NFS folder
              # config.vm.synced_folder "shared/nfs/", "/vagrant/", type: "nfs"
              config.vm.synced_folder "shared/nfs/", "/vagrant/"
  
          end # config.vm.define opts[:name] do |config|
  
      end # app_servers.each
  </code></pre>
  
  <p>I also have a provision/web11-provision.sh file (but no web21 or learninglocker equivalents) which basically just prints out a message for now. </p>
  
  <p>The problem: When running a vagrant up when it brings up web11 it prints the message that the file exists (expected). When it brings up web21, boxname is still web11 on first go around and so runs the provisioning script, then it goes again and changes to web21 so doesn't find the file. The same thing happens for learninglocker - runs web11, then web21, then learninglocker.</p>
  
  <p>I'm clearly being dumb in terms of my .each statement, but can't figure out what it is... help?</p>
  
  <p>Here's the full output of the vagrant up...</p>
  
  <pre><code>vagrant up     
  Bringing machine 'web11' up with 'virtualbox' provider...
  Bringing machine 'web21' up with 'virtualbox' provider...
  Bringing machine 'learninglocker' up with 'virtualbox' provider...
  Bringing machine 'db22' up with 'virtualbox' provider...
  Bringing machine 'db23' up with 'virtualbox' provider...
  Bringing machine 'loadbalancer' up with 'virtualbox' provider...
  ==&gt; web11: Importing base box 'puppetlabs/centos-6.5-64-puppet'...
  ==&gt; web11: Matching MAC address for NAT networking...
  ==&gt; web11: Checking if box 'puppetlabs/centos-6.5-64-puppet' is up to date...
  ==&gt; web11: Setting the name of the VM: verf_web11_1413999007267_1427
  ==&gt; web11: Clearing any previously set network interfaces...
  ==&gt; web11: Preparing network interfaces based on configuration...
      web11: Adapter 1: nat
      web11: Adapter 2: hostonly
  ==&gt; web11: Forwarding ports...
      web11: 22 =&gt; 2222 (adapter 1)
      web11: 811 =&gt; 8811 (adapter 1)
  ==&gt; web11: Booting VM...
  ==&gt; web11: Waiting for machine to boot. This may take a few minutes...
      web11: SSH address: 127.0.0.1:2222
      web11: SSH username: vagrant
      web11: SSH auth method: private key
      web11: Warning: Connection timeout. Retrying...
  ==&gt; web11: Machine booted and ready!
  ==&gt; web11: Checking for guest additions in VM...
  ==&gt; web11: Setting hostname...
  ==&gt; web11: Configuring and enabling network interfaces...
  ==&gt; web11: Mounting shared folders...
      web11: /vagrant =&gt; /Users/mbcx9rvt/Sites/UBC/CTLT/installs/spaces/vagrant/verf/shared/nfs
  ==&gt; web11: Running provisioner: shell...
      web11: Running: inline script
  web11-provision.sh
  ==&gt; web11: Running provisioner: shell...
      web11: Running: inline script
  +++exists+++
  ==&gt; web11: Running provisioner: shell...
      web11: Running: /var/folders/c6/1yd6r3px03j_l3f4g0kfkjfm0000gn/T/vagrant-shell20141022-35420-ulkjfx
  Check for apt packages to install...
  httpd,
  php,
  php-gd,
  php-pear,
  php-xml,
  php-xmlrpc,
  php-mbstring,
  php-mcrypt,
  php-tidy,
  curl,
  curl-devel,
  php-pecl-apc
  No yum packages to install.
  
  ==&gt; web11: Running provisioner: shell...
      web11: Running: inline script
  !!!thisname!!!! web11
  ==&gt; web11: Running provisioner: shell...
      web11: Running: inline script
  !!!thisip!!!! 192.168.1.811
  ==&gt; web11: Checking for host entries
  ==&gt; web11: adding to (/etc/hosts) : 192.168.1.811  web11.vagrant  # VAGRANT: 71c96f7d0c293c081643fe8aeec588e3 (web11) / 1e8cff2f-4e26-4b70-99eb-e62e9b976413
  ==&gt; web21: Importing base box 'puppetlabs/centos-6.5-64-puppet'...
  ==&gt; web21: Matching MAC address for NAT networking...
  ==&gt; web21: Checking if box 'puppetlabs/centos-6.5-64-puppet' is up to date...
  ==&gt; web21: Setting the name of the VM: verf_web21_1413999051481_37940
  ==&gt; web21: Fixed port collision for 22 =&gt; 2222. Now on port 2200.
  ==&gt; web21: Clearing any previously set network interfaces...
  ==&gt; web21: Preparing network interfaces based on configuration...
      web21: Adapter 1: nat
      web21: Adapter 2: hostonly
  ==&gt; web21: Forwarding ports...
      web21: 22 =&gt; 2200 (adapter 1)
      web21: 821 =&gt; 8821 (adapter 1)
  ==&gt; web21: Booting VM...
  ==&gt; web21: Waiting for machine to boot. This may take a few minutes...
      web21: SSH address: 127.0.0.1:2200
      web21: SSH username: vagrant
      web21: SSH auth method: private key
      web21: Warning: Connection timeout. Retrying...
  ==&gt; web21: Machine booted and ready!
  ==&gt; web21: Checking for guest additions in VM...
  ==&gt; web21: Setting hostname...
  ==&gt; web21: Configuring and enabling network interfaces...
  ==&gt; web21: Mounting shared folders...
      web21: /vagrant =&gt; /Users/mbcx9rvt/Sites/UBC/CTLT/installs/spaces/vagrant/verf/shared/nfs
  ==&gt; web21: Running provisioner: shell...
      web21: Running: inline script
  web11-provision.sh
  ==&gt; web21: Running provisioner: shell...
      web21: Running: inline script
  +++exists+++
  ==&gt; web21: Running provisioner: shell...
      web21: Running: /var/folders/c6/1yd6r3px03j_l3f4g0kfkjfm0000gn/T/vagrant-shell20141022-35420-1bv1h0u
  Check for apt packages to install...
  httpd,
  php,
  php-gd,
  php-pear,
  php-xml,
  php-xmlrpc,
  php-mbstring,
  php-mcrypt,
  php-tidy,
  curl,
  curl-devel,
  php-pecl-apc
  No yum packages to install.
  
  ==&gt; web21: Running provisioner: shell...
      web21: Running: inline script
  web21-provision.sh
  ==&gt; web21: Running provisioner: shell...
      web21: Running: inline script
  PROVISION FILE DOES NOT EXIST!
  ==&gt; web21: Running provisioner: shell...
      web21: Running: inline script
  !!!thisname!!!! web21
  ==&gt; web21: Running provisioner: shell...
      web21: Running: inline script
  !!!thisip!!!! 192.168.1.821
  ==&gt; web21: Checking for host entries
  ==&gt; web21: adding to (/etc/hosts) : 192.168.1.821  web21.vagrant  # VAGRANT: ed18947cb0a37a2d7811d08949b44331 (web21) / b33cde0c-da4f-4739-9f0e-332f0bfd1b67
  ==&gt; learninglocker: Importing base box 'puppetlabs/centos-6.5-64-puppet'...
  ==&gt; learninglocker: Matching MAC address for NAT networking...
  ==&gt; learninglocker: Checking if box 'puppetlabs/centos-6.5-64-puppet' is up to date...
  ==&gt; learninglocker: Setting the name of the VM: verf_learninglocker_1413999103267_74239
  ==&gt; learninglocker: Fixed port collision for 22 =&gt; 2200. Now on port 2201.
  ==&gt; learninglocker: Clearing any previously set network interfaces...
  ==&gt; learninglocker: Preparing network interfaces based on configuration...
      learninglocker: Adapter 1: nat
      learninglocker: Adapter 2: hostonly
  ==&gt; learninglocker: Forwarding ports...
      learninglocker: 22 =&gt; 2201 (adapter 1)
      learninglocker: 899 =&gt; 8899 (adapter 1)
  ==&gt; learninglocker: Booting VM...
  ==&gt; learninglocker: Waiting for machine to boot. This may take a few minutes...
      learninglocker: SSH address: 127.0.0.1:2201
      learninglocker: SSH username: vagrant
      learninglocker: SSH auth method: private key
      learninglocker: Warning: Connection timeout. Retrying...
  ==&gt; learninglocker: Machine booted and ready!
  ==&gt; learninglocker: Checking for guest additions in VM...
  ==&gt; learninglocker: Setting hostname...
  ==&gt; learninglocker: Configuring and enabling network interfaces...
  ==&gt; learninglocker: Mounting shared folders...
      learninglocker: /vagrant =&gt; /Users/mbcx9rvt/Sites/UBC/CTLT/installs/spaces/vagrant/verf/shared/nfs
  ==&gt; learninglocker: Running provisioner: shell...
      learninglocker: Running: inline script
  web11-provision.sh
  ==&gt; learninglocker: Running provisioner: shell...
      learninglocker: Running: inline script
  +++exists+++
  ==&gt; learninglocker: Running provisioner: shell...
      learninglocker: Running: /var/folders/c6/1yd6r3px03j_l3f4g0kfkjfm0000gn/T/vagrant-shell20141022-35420-17ptv1r
  Check for apt packages to install...
  httpd,
  php,
  php-gd,
  php-pear,
  php-xml,
  php-xmlrpc,
  php-mbstring,
  php-mcrypt,
  php-tidy,
  curl,
  curl-devel,
  php-pecl-apc
  No yum packages to install.
  
  ==&gt; learninglocker: Running provisioner: shell...
      learninglocker: Running: inline script
  web21-provision.sh
  ==&gt; learninglocker: Running provisioner: shell...
      learninglocker: Running: inline script
  PROVISION FILE DOES NOT EXIST!
  ==&gt; learninglocker: Running provisioner: shell...
      learninglocker: Running: inline script
  learninglocker-provision.sh
  ==&gt; learninglocker: Running provisioner: shell...
      learninglocker: Running: inline script
  PROVISION FILE DOES NOT EXIST!
  ==&gt; learninglocker: Running provisioner: shell...
      learninglocker: Running: inline script
  !!!thisname!!!! learninglocker
  ==&gt; learninglocker: Running provisioner: shell...
      learninglocker: Running: inline script
  !!!thisip!!!! 192.168.1.899
  ==&gt; learninglocker: Checking for host entries
  ==&gt; learninglocker: adding to (/etc/hosts) : 192.168.1.899  learninglocker.vagrant  # VAGRANT: 36d4e82ec2f09084a7e5cd6ebb66c900 (learninglocker) / c338507a-aa8e-41fa-af79-04deb0e124d2
  </code></pre>