Port redirection and provisioning

14 views
Skip to first unread message

John Schank

unread,
Nov 4, 2015, 11:20:30 AM11/4/15
to Vagrant
Hello,
I would like to be able to detect the port redirection that gets used (i.e. after collisions are resolved) within my vagrant file so that I can pass the port information into a provisioning step.
Is such a thing possible.

Let me explain why I want to do this:
I am spinning up a VM for Wordpress development, and the wordpress instance needs to know the port, so that the site_url can include it. (for example: localhost:8888)
Since the port could collide and vagrant will choose another port, I would like to be able to retrieve this port, and then pass it to a provisioning step, so that the wordpress
instance in the guest os can be updated to "know" the new port.

Does anyone have some advice on this topic? All ideas welcome.

Thanks,
John Schank

Alvaro Miranda Aguilera

unread,
Nov 5, 2015, 5:50:33 AM11/5/15
to vagra...@googlegroups.com
Hello John

If you need a simple (1 site) Vagrant project for WordPress I did this:

https://github.com/kikitux/wp-vagrant

For more complex, you can check here:
http://salferrarello.com/vagrant-vvv-setup-wordpress/

They talk about site_url, sadly I am not familiar with that.

So here some more info from the Vagrant side:


Not sure what are you using for Virtualization or cloud, so I will
assume virtualbox.

If that's the case, the best will be give a private_network to each
VM, so you can have a known fixed ip, and then you can use

http://<fixedip>:80 directly

If you require other computers in the network would require access to
this VM, you can use public_network that will bridge to the network
you are using. there you can just let dhcp to give one, or ask for a
fixed IP for the VM.

For the first scenario, you can check here:
https://docs.vagrantup.com/v2/networking/private_network.html

You can add this to the Vagranfile

config.vm.network "private_network", ip: "192.168.50.4"

And that IP (or any other) will be assigned to the VM.

Hope this helps
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 vagrant-up+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vagrant-up/ef66ae69-f665-4d57-b1c9-0ba532fca7a4%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Joaquin Menchaca

unread,
Nov 13, 2015, 8:18:50 PM11/13/15
to Vagrant
Thank you Alvaro.  Triggers* look awesome, I can use them to download some packages with curl and have them available when I provision systems.

Reply all
Reply to author
Forward
0 new messages