How to get a machine/node name from within a define block?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get a machine/node name from within a define block?

Rui Lopes
Is there a way to get server1 and server2 from within a config.vm.define block?

For example, how can I do it in the following Vagrantfile?

config.vm.define "server1" do |config|
  puts TODO-what-variable-will-get-me-server1?
end

config.vm.define "server2" do |config|
  puts TODO-what-variable-will-get-me-server1?
end

Do I really need to use a temporary variable? e.g. something like:

node1_name = 'server1'
config.vm.define node1_name do |config|
  puts node1_name
end

node2_name = 'server2'
config.vm.define node2_name do |config|
  puts node2_name
end

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 the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/43ee4ed4-0c2e-407b-ad1f-be29fe37ee0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to get a machine/node name from within a define block?

Alvaro Miranda Aguilera
Hello

This works for me:


Vagrant.configure("2") do |config|

  config.vm.box = "hashicorp/precise64"


  (1..2).each do |i|

    config.vm.define vm_name = "dc1-web0%01d" % i do |web|

      puts vm_name

      web.vm.hostname = "#{vm_name}"

    end

  end

end



Alvaro

On Wed, Jul 26, 2017 at 6:41 PM, Rui Lopes <[hidden email]> wrote:
Is there a way to get server1 and server2 from within a config.vm.define block?

For example, how can I do it in the following Vagrantfile?

config.vm.define "server1" do |config|
  puts TODO-what-variable-will-get-me-server1?
end

config.vm.define "server2" do |config|
  puts TODO-what-variable-will-get-me-server1?
end

Do I really need to use a temporary variable? e.g. something like:

node1_name = 'server1'
config.vm.define node1_name do |config|
  puts node1_name
end

node2_name = 'server2'
config.vm.define node2_name do |config|
  puts node2_name
end

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 the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/43ee4ed4-0c2e-407b-ad1f-be29fe37ee0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0ewoP7Jaify%2B2mv18%2B6RNuufic0c%3D6vZEYc3mAAkCyywMA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to get a machine/node name from within a define block?

Rui Lopes
Hello, oh so we really need to use a temporary variable? I was looking for some other solution, like having the name somewhere at the config object :-/

On Thursday, July 27, 2017 at 5:49:27 AM UTC+1, Alvaro Miranda Aguilera wrote:
Hello

This works for me:


Vagrant.configure("2") do |config|

  config.vm.box = "hashicorp/precise64"


  (1..2).each do |i|

    config.vm.define vm_name = "dc1-web0%01d" % i do |web|

      puts vm_name

      web.vm.hostname = "#{vm_name}"

    end

  end

end



Alvaro

On Wed, Jul 26, 2017 at 6:41 PM, Rui Lopes <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="MbdXrxcLAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rui.godi...@...> wrote:
Is there a way to get server1 and server2 from within a config.vm.define block?

For example, how can I do it in the following Vagrantfile?

config.vm.define "server1" do |config|
  puts TODO-what-variable-will-get-me-server1?
end

config.vm.define "server2" do |config|
  puts TODO-what-variable-will-get-me-server1?
end

Do I really need to use a temporary variable? e.g. something like:

node1_name = 'server1'
config.vm.define node1_name do |config|
  puts node1_name
end

node2_name = 'server2'
config.vm.define node2_name do |config|
  puts node2_name
end

Thanks!

--
This mailing list is governed under the HashiCorp Community Guidelines - <a href="https://www.hashicorp.com/community-guidelines.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.hashicorp.com%2Fcommunity-guidelines.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGHa_CaKfZaJiwbkUndUQbVGlQCDw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.hashicorp.com%2Fcommunity-guidelines.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGHa_CaKfZaJiwbkUndUQbVGlQCDw&#39;;return true;">https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: <a href="https://github.com/mitchellh/vagrant/issues" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmitchellh%2Fvagrant%2Fissues\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHxcA5DuHlQlPInMi_k1Pz4pMNqNw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmitchellh%2Fvagrant%2Fissues\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHxcA5DuHlQlPInMi_k1Pz4pMNqNw&#39;;return true;">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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="MbdXrxcLAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">vagrant-up+...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/vagrant-up/43ee4ed4-0c2e-407b-ad1f-be29fe37ee0e%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/vagrant-up/43ee4ed4-0c2e-407b-ad1f-be29fe37ee0e%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/vagrant-up/43ee4ed4-0c2e-407b-ad1f-be29fe37ee0e%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/vagrant-up/43ee4ed4-0c2e-407b-ad1f-be29fe37ee0e%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.



--
Alvaro

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/2a7d0f69-7142-483d-86a3-c9236dc95999%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.