also, the vagrant-hostmanager plugin does this for you. 
https://github.com/devopsgroup-io/vagrant-hostmanager



On Tuesday, July 26, 2016 at 11:19:48 PM UTC-7, Soham Chakraborty wrote:
>
> Hi, 
>
> I have a four node vagrant setup that I am using to test puppet. What I 
> intend to do is to add the FQDN of the puppetmaster node to the 2nd line of 
> the /etc/hosts of the other 3 nodes. The Vagrantfile is thus: 
>
> # -*- mode: ruby -*-
> # vi: set ft=ruby :
> #
> #
> Vagrant.configure(2) do |config|
>   config.vm.box = "ubuntu/trusty64"
>   config.vm.provision "shell", path: "script.sh"
>
>   config.vm.define "puppetmaster" do |puppetmaster|
>     puppetmaster.vm.network :private_network, ip: "192.168.33.33"
>     puppetmaster.vm.network :forwarded_port, guest: 80, host: 8080
>     puppetmaster.vm.network :forwarded_port, guest: 8140, host: 8141
>     puppetmaster.vm.hostname = "puppetmaster.example.com"
>   end
>
>   config.vm.define "web" do |web|
>     web.vm.network :private_network, ip: "192.168.33.34"
>     web.vm.network :forwarded_port, guest: 8140, host: 8142
>     web.vm.hostname = "web.example.com"
>   end
>
>   config.vm.define "mail" do |mail|
>     mail.vm.network :private_network, ip: "192.168.33.35"
>     mail.vm.network :forwarded_port, guest: 8140, host: 8143
>     mail.vm.hostname = "mail.example.com"
>   end
>
>   config.vm.define "db" do |db|
>     db.vm.network :private_network, ip: "192.168.33.36"
>     db.vm.network :forwarded_port, guest: 8140, host: 8144
>     db.vm.hostname = "db.example.com"
>   end
>
> end
>
> script.sh is used for updating the vm, otherwise puppet-common won't be 
> installed. 
>
> $ cat script.sh 
> sudo apt-get update -y
> sudo apt-get install puppet -y
>
> With this setup, after the four machines boot up, I go to web, db and mail 
> vms and do a sed -i "2i 192.168.33.33 puppetmaster.example.com puppet" 
> /etc/hosts to include the FQDN of the puppetmaster host. 
>
> 1) Can this be accomplished by any method inside the Vagrantfile or in 
> script.sh? 
>
> 2) Also, any critique to write the Vagrantfile better will be appreciated. 
> I feel like maintaining the file like I do now can be a bit cumbersome when 
> I add more machines or want to do specific things to specific nodes. I 
> don't have a specific example right now, this is just a thought. 
>
> Thanks guys!
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vagrant-up/ec5d2171-5e5b-461b-a52f-c88ec0fa146d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to