Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple private_network adapters #58

Closed
mefellows opened this issue Feb 2, 2015 · 7 comments
Closed

Support for multiple private_network adapters #58

mefellows opened this issue Feb 2, 2015 · 7 comments
Labels

Comments

@mefellows
Copy link

Given the following Vagrant setup, vagrant-hostsupdater produces an invalid /etc/hosts file where different hostnames need to be bound to different IP addresses within the guest:

  ip_address_au = "10.0.0.28"
  ip_address_nz = "10.0.0.29"
  config.vm.network "private_network", ip: ip_address_nz
  config.vm.network "private_network", ip: ip_address_au

  if Vagrant.has_plugin?("vagrant-hostsupdater")
    config.hostsupdater.aliases = ["foo.com", "bar.com"}
  end
  ...

The /etc/hosts file will look something like:

10.0.0.28  foo.com  # VAGRANT: 76d2a8f38ca5dad7d0414a3dc013813c (default) / 234b3f77-7624-4b98-8ce1-5560abeb4ff7
10.0.0.28  bar.com  # VAGRANT: 76d2a8f38ca5dad7d0414a3dc013813c (default) / 234b3f77-7624-4b98-8ce1-5560abeb4ff7
10.0.0.29  foo.com  # VAGRANT: 72750f9e895980fb84e2792fd10a90f3 (default) / 5571d2f0-bb3e-4897-b151-394a8db63b05
10.0.0.29  foo.com  # VAGRANT: 72750f9e895980fb84e2792fd10a90f3 (default) / 5571d2f0-bb3e-4897-b151-394a8db63b05b

It would be great if support for mapping IPs to hostnames were added:

e.g. a syntax something like:

    config.hostsupdater.aliases = {ip_address_au => ["foo.com"], ip_address_nz => ["bar.com"]}

would produce a hosts file like:

10.0.0.28  foo.com  # VAGRANT: 76d2a8f38ca5dad7d0414a3dc013813c (default) / 234b3f77-7624-4b98-8ce1-5560abeb4ff7
10.0.0.29  bar.com  # VAGRANT: 72750f9e895980fb84e2792fd10a90f3 (default) / 5571d2f0-bb3e-4897-b151-394a8db63b05b
mefellows added a commit to mefellows/vagrant-multi-hostsupdater that referenced this issue Feb 2, 2015
…ames, with backwards-compatible syntax for existing setups (see this issue for details: agiledivider#58)
@chuckd
Copy link

chuckd commented Aug 3, 2015

@mefellows we have exactly the same requirement, down to separate IPs for AU and NZ :). Would be grateful if you got a chance to craft up a suitable PR, otherwise I'll have a go based on your work.

@mefellows
Copy link
Author

Hi @chuckd, take a look at https://github.com/SEEK-Jobs/vagrant-multi-hostsupdater. We use it a SEEK and it works nicely.

There is an old PR for this project but there hasn't been any activity in a while.

@chuckd
Copy link

chuckd commented Aug 3, 2015

Ah, nice, thanks @mefellows, looks perfect, I'll give that a go.

@cgsmith
Copy link
Collaborator

cgsmith commented Nov 4, 2015

Hi @mefellows! This looks like it would be a good addition and I can definitely see the need for this as @chuckd does.

Would you be willing to resubmit a PR branched from or submitted to develop ?

@cgsmith cgsmith added this to the 0.13 milestone Nov 4, 2015
@cgsmith cgsmith removed this from the 0.13 milestone Dec 8, 2015
@mefellows
Copy link
Author

Hi @cgsmith - sorry I don't know how I missed this! I'll take a look at the fork and see what I can do. Given this has good visibility it would be nice to contribute back.

@maximerety
Copy link
Contributor

Hi guys!

I would also really like to see this feature land, so I resubmitted a PR branched from develop: #96

The code is slightly different from @mefellows' commit to handle config.vm.hostname as before, even when a hash of aliases is given (and does not contain an alias with the same host), i.e.

config.vm.network :private_network, ip: "10.0.0.28"
config.vm.network :private_network, ip: "10.0.0.29"

# example 1:
config.vm.hostname = "dev.host.com"
config.hostsupdater.aliases = { "10.0.0.29" => "ftp.host.com" }
# in /etc/hosts: 
#   10.0.0.28       dev.host.com
#   10.0.0.29       dev.host.com
#   10.0.0.29       ftp.host.com

# example 2:
config.vm.hostname = "dev.host.com"
config.hostsupdater.aliases = { "10.0.0.28" => "dev.host.com", "10.0.0.29" => "ftp.host.com" }
# in /etc/hosts: 
#   10.0.0.28       dev.host.com
#   10.0.0.29       ftp.host.com

The original behavior is not changed when an array is given for the aliases option.

The comments in README.md have been shamelessly stolen from @mefellows' PR.

I hope this can help.

@cgsmith
Copy link
Collaborator

cgsmith commented Mar 30, 2018

This has been merged in and is part of the release.

@cgsmith cgsmith closed this as completed Mar 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants