Creating Dynamic hostname

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

Creating Dynamic hostname

Abhishek Verma
Hi All,

I am trying to setup a Vagrant machine with dynamic hostname.

I can setup hostname using "config.vm.hostname = "DummyReefServer"" in VagrantFile and it works fine.
But I wish to make this hostname dynamic , if possibile based on macaddress so everytime its unique..

Is it possible to setup hostname dunamic possibly something like this

config.vm.hostname = "DummyReefServer"+ethernet0.address

Thanks in Advance

Regards,
Abhishek

--
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/270f87fb-6bf0-48c7-a676-25ce8d16e256%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Creating Dynamic hostname

Alvaro Miranda Aguilera
Hello

Not sure about mac, but you can use:

SecureRandom.random_number(99999)


Adjust the number of digits.


Alvaro


On Tue, May 2, 2017 at 5:34 PM, Abhishek Verma <[hidden email]> wrote:
Hi All,

I am trying to setup a Vagrant machine with dynamic hostname.

I can setup hostname using "config.vm.hostname = "DummyReefServer"" in VagrantFile and it works fine.
But I wish to make this hostname dynamic , if possibile based on macaddress so everytime its unique..

Is it possible to setup hostname dunamic possibly something like this

config.vm.hostname = "DummyReefServer"+ethernet0.address

Thanks in Advance

Regards,
Abhishek

--
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/270f87fb-6bf0-48c7-a676-25ce8d16e256%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/CAHqq0ez-U%3DzLOq9Atv2P160_ahXRb1X2WHJ3%2BfUZ%2BNkhzodOjg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Creating Dynamic hostname

Abhishek Verma
Hi Alvaro,
Thanks for your reply. I can now create a unique mac address using
config.vm.hostname = "dummy-ngs-#{SecureRandom.random_number(9999)}"

but every time I reboot my machine , hostname gets reset.
i want to create unique hostname for machine when I create it, till i destroy it.

Any suggestions?

On Tuesday, May 2, 2017 at 8:32:55 PM UTC+1, Alvaro Miranda Aguilera wrote:
Hello

Not sure about mac, but you can use:

SecureRandom.random_number(99999)


Adjust the number of digits.


Alvaro


On Tue, May 2, 2017 at 5:34 PM, Abhishek Verma <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="JTp1yAJBBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">abhishe...@...> wrote:
Hi All,

I am trying to setup a Vagrant machine with dynamic hostname.

I can setup hostname using "config.vm.hostname = "DummyReefServer"" in VagrantFile and it works fine.
But I wish to make this hostname dynamic , if possibile based on macaddress so everytime its unique..

Is it possible to setup hostname dunamic possibly something like this

config.vm.hostname = "DummyReefServer"+ethernet0.address

Thanks in Advance

Regards,
Abhishek

--
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="JTp1yAJBBgAJ" 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/270f87fb-6bf0-48c7-a676-25ce8d16e256%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/270f87fb-6bf0-48c7-a676-25ce8d16e256%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/vagrant-up/270f87fb-6bf0-48c7-a676-25ce8d16e256%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/vagrant-up/270f87fb-6bf0-48c7-a676-25ce8d16e256%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/735dac67-7500-4641-9e8c-5c3d7eb4b454%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Creating Dynamic hostname

Jamie Jackson
Maybe you could write the value to a file on the host, somewhere in
the vagrant directory (only if the file doesn't exist already), then
read it in from the file. I do a lot of this kind of thing to create
idempotent provisioners.

On Tue, May 2, 2017 at 5:33 PM, Abhishek Verma
<[hidden email]> wrote:

> Hi Alvaro,
> Thanks for your reply. I can now create a unique mac address using
> config.vm.hostname = "dummy-ngs-#{SecureRandom.random_number(9999)}"
>
> but every time I reboot my machine , hostname gets reset.
> i want to create unique hostname for machine when I create it, till i
> destroy it.
>
> Any suggestions?
>
> On Tuesday, May 2, 2017 at 8:32:55 PM UTC+1, Alvaro Miranda Aguilera wrote:
>>
>> Hello
>>
>> Not sure about mac, but you can use:
>>
>> SecureRandom.random_number(99999)
>>
>>
>> Adjust the number of digits.
>>
>>
>> Alvaro
>>
>>
>> On Tue, May 2, 2017 at 5:34 PM, Abhishek Verma <[hidden email]>
>> wrote:
>>>
>>> Hi All,
>>>
>>> I am trying to setup a Vagrant machine with dynamic hostname.
>>>
>>> I can setup hostname using "config.vm.hostname = "DummyReefServer"" in
>>> VagrantFile and it works fine.
>>> But I wish to make this hostname dynamic , if possibile based on
>>> macaddress so everytime its unique..
>>>
>>> Is it possible to setup hostname dunamic possibly something like this
>>>
>>> config.vm.hostname = "DummyReefServer"+ethernet0.address
>>>
>>> Thanks in Advance
>>>
>>> Regards,
>>> Abhishek
>>>
>>> --
>>> 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/270f87fb-6bf0-48c7-a676-25ce8d16e256%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/735dac67-7500-4641-9e8c-5c3d7eb4b454%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
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/CA%2BonWPfE9206xRLvCjO5DGgFUC4kN9WNEDVfiWs-U5qb4YJTSw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Creating Dynamic hostname

Alvaro Miranda Aguilera
In reply to this post by Abhishek Verma
try something like this:

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

  File.open("hostname.txt", "w") {|f| f.write("dummy-ngs-#{SecureRandom.random_number(9999)}")} unless File.file?("hostname.txt")

  hostname = File.read("hostname.txt")


  config.vm.hostname = hostname

  config.vm.box = "hashicorp/precise64"

end

--
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/CAHqq0eybpdJxaazonwk5ZbQX8QrW%2BW-z5FDZH%3DJq5LWbXGMJSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Creating Dynamic hostname

Abhishek Verma
Hey Guys , 
Thanks alot for your help.
Finally I found many ways to do the same thing. 
1. As Alvaro suggested, write to a temp file, 
2. or use Script inside VagrantFile to write to temp file
3. Create a script inside vagrant machine which runs on bootup , and repackage vagrant machine 
4. use provisioning and create a shell script next to VagrantFile which runs on bootup and configures the machine.

I went with number 4. (because i had to use macaddress not random numbers).
Although I wanted to set it up inside VagrantFile so machine has hostname before bootup, but I couldnt find out way to get macaddress and create a hostname string in VagrantFile. (New to Vagrant and dont know Ruby.)

But never mind, i got what I want .

Thanks to you all again.

Regards,
Abhishek


On Wed, May 3, 2017 at 11:41 AM, Alvaro Miranda Aguilera <[hidden email]> wrote:
try something like this:

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

  File.open("hostname.txt", "w") {|f| f.write("dummy-ngs-#{SecureRandom.random_number(9999)}")} unless File.file?("hostname.txt")

  hostname = File.read("hostname.txt")


  config.vm.hostname = hostname

  config.vm.box = "hashicorp/precise64"

end

--
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/rXpN5TCCFUo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0eybpdJxaazonwk5ZbQX8QrW%2BW-z5FDZH%3DJq5LWbXGMJSg%40mail.gmail.com.

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

--
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/CA%2B6Ho8_Y6_B4a2SqWZyeU%3DLQM%3DLfsXCvf0M%3Dd7Gp1DW_AZGEcQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.