Printing final message at end of Vagrantfile that creates multiple VMs

18 views
Skip to first unread message

Juan Jiménez

unread,
Oct 1, 2017, 2:05:29 PM10/1/17
to Vagrant
I want to puts a message at the very end of all processing of my Vagrantfile, but I can't use the config.vm.post_up_message because I am creating three vm's in a dev cluster and I don't want the message shown three times. Any ideas?

Alvaro Miranda Aguilera

unread,
Oct 2, 2017, 3:13:45 AM10/2/17
to vagra...@googlegroups.com
on the last VM block, say its "web01" you can put

web01.vm.post_up_message

On Sun, Oct 1, 2017 at 8:05 PM, Juan Jiménez <fly...@gmail.com> wrote:
I want to puts a message at the very end of all processing of my Vagrantfile, but I can't use the config.vm.post_up_message because I am creating three vm's in a dev cluster and I don't want the message shown three times. Any ideas?

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/cc05b644-e8df-46ea-b5fa-c43a590d4f79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Juan Jiménez

unread,
Oct 2, 2017, 6:30:26 AM10/2/17
to vagra...@googlegroups.com
There is only one VM block and a loop to create the three VM's. They are essentially identical, with small differences, so no point in copying everything three times. That is why this solution does not work.

You received this message because you are subscribed to a topic in the Google Groups "Vagrant" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vagrant-up/065bLYW4YpY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0eytrgEBqyuzYTi8%3DON0T9KT3roXtcL0zhC1bDwCk9HtpA%40mail.gmail.com.

Alvaro Miranda Aguilera

unread,
Oct 2, 2017, 4:12:28 PM10/2/17
to vagra...@googlegroups.com
you can *if* on the loop

say you loop 0 to 2 on a var i

web01.vm.post_up_message = "hello" if i==2



please share the vagrantfile so I can test and share a working example

Alvaro


For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Juan Jiménez

unread,
Oct 2, 2017, 4:17:52 PM10/2/17
to vagra...@googlegroups.com
The if *after* the post_up_message??

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
#------
# Spin up three VM's, set hostnames and assign IP's.
#------
(1..3).each do |i|
  config.vm.define "node#{i}" do |node|
    node.vm.box = "ubuntu/xenial64"
    node.vm.hostname = "node#{i}"
    node.vm.network "private_network", ip: "192.168.50.1#{i}"
#-----
# Each VM needs to have two block devices. 1GB local storage each
# for the purpose of this exercise, and attached to the VM's.
#-----
    node.vm.provider "virtualbox" do |vb|
#-----
# If disks don't already exist, create them.
#-----
      unless FileTest.exist?("node#{i}_disk1.vdi")
       vb.customize ['createhd', '--filename', "node#{i}_disk1.vdi", '--variant', 'Fixed', '--size', 1 * 1024]
      end
      unless FileTest.exist?("node#{i}_disk2.vdi")
       vb.customize ['createhd', '--filename', "node#{i}_disk2.vdi", '--variant', 'Fixed', '--size', 1 * 1024]
      end
#-----
# Attach the drives to the SCSI controller.
#-----
# !! NOTE: This step is specific to the ubuntu/xenial64 box.
# !!       If you change the box, these next two commands will likely fail!
# !!       (Extra credit if you can figure out *why* they will likely fail.)
#-----
      vb.customize ['storageattach', :id,  '--storagectl', 'SCSI', '--port', 2, '--device', 0, '--type', 'hdd', '--medium', "node#{i}_disk1.vdi"]
      vb.customize ['storageattach', :id,  '--storagectl', 'SCSI', '--port', 3, '--device', 0, '--type', 'hdd', '--medium', "node#{i}_disk2.vdi"]
    end
#-----
# Do all the common configuration work
#-----
    node.vm.provision "shell", path: "./provision/common.sh"
#-----
# Configure and setup the Consul and Nomad clusters
#-----
    case i
      when 1
        node.vm.provision "shell", path: "./provision/consulserver.sh"
        node.vm.provision "shell", path: "./provision/nomadserver.sh"
      when 2
        node.vm.provision "shell", path: "./provision/consulagent1.sh" 
        node.vm.provision "shell", path: "./provision/nomadclient1.sh"
      when 3
        node.vm.provision "shell", path: "./provision/consulagent2.sh"
        node.vm.provision "shell", path: "./provision/nomadclient2.sh"
    end
#----
# Configure and run cadvisor with Nomad
#----
    node.vm.provision "shell", path: "./provision/cadvisor.sh"
  end
end
end


Alvaro Miranda Aguilera

unread,
Oct 2, 2017, 4:20:11 PM10/2/17
to vagra...@googlegroups.com
yes its a ruby format

but you can add the message you want to this block:

      when 3
        node.vm.provision "shell", path: "./provision/consulagent2.sh"
        node.vm.provision "shell", path: "./provision/nomadclient2.sh"
        # <here the message you want>
    end

Juan Jiménez

unread,
Oct 2, 2017, 5:13:54 PM10/2/17
to vagra...@googlegroups.com
Thanks!

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to a topic in the Google Groups "Vagrant" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vagrant-up/065bLYW4YpY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vagrant-up+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages