Open waldoj opened 11 years ago
I wasn't happy with the state of my code — very much hardcoded junk that I've just been manually changing. Here is a much better solution!
That looks perfect—thanks so much, Mark!
Also, it looks like Vagrant plugins are installed globally, and there is no canonical way to install them from within a Vagrantfile. So this is what I rigged up:
# Install the required plugins
def require_plugin plugin
puts `cd ~/ >/dev/null && vagrant plugin install #{plugin}` unless `cd ~/ && vagrant plugin list`.chomp.split("\n").select{|x| x.include? plugin}.length > 0
end
require_plugin 'vagrant-hostsupdater'
Why the cd
? Because if the vagrant
command is run from within a Vagrantfile
-containing directory, you get an infinite loop. :smile:
This works a charm!
config.vm.hostname = "example.com"
config.vm.network :private_network, :ip => "192.168.50.4"
config.hostsupdater.aliases = %w{www.example.com foo.example.com}
config.hostsupdater.remove_on_suspend = true
Don't forget the remove_on_suspend
part. Not sure why that isn't the default.
@markjaquith I could not get the hostupdater plugin to work with Vagrant 1.3.4. Did it definitely work for you? What OS are you using?
Definitely works. OS X.
@markjaquith I just re-downloaded statedecoded-vagrant and ran vagrant-up
. I get an error.
Vagrant:
* Unknown configuration section 'hostsupdater'.
Here is asciinema of it: http://asciinema.org/a/5834
Seems to work if I install the plugin from the host command line before running vagrant up
.
bash-3.2$ vagrant plugin install vagrant-hostsupdater
Installing the 'vagrant-hostsupdater' plugin. This can take a few minutes...
Installed the plugin 'vagrant-hostsupdater (0.0.10)'!
bash-3.2$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise64'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
...
Huh. Odd. That code snippet I provided should have auto-installed it if it wasn't present.
I previously tried a variety of ways to have vagrant install the plugin from within running the file but with no luck either so far. Have you tried uninstalling the plugin on you system and then running vagrant up
to see if you can replicate what I am encountering?
The plugins would be awesome if Vagrant installed them while running the Vagrantfile. (And a bit odd vagrant does not considering how much automated magic it does.
@gregelin, this might call for opening a ticket on @cogitatio's repository for Vagrant::Hostsupdater. Getting a development domain working isn't crucial for The State Decoded, but it's surely going to be important for y'all to be able to get working reliably!
PuPHPet insists on setting up a VirtualHost, but that necessitates editing
/etc/hosts
in order to map that virtual host properly. @markjaquith has somelocaldev
Vagrant code that will resolve that. This may, as a result, resolve #1, too.