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. |
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:
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. |
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:
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. |
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. |
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. |
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:
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. |
Free forum by Nabble | Edit this page |