Enhancement Request: Automatic hostname generation in multimachine environment
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 27.2k
- Forks
- 4.4k
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
It would be useful to allow using some internal values somewhere else.
Let me explain it using hostnames, as it's a good example of what features would be useful, but also it represents an existing problem. Generating proper multimachine environment is cumbersome now. If I set several machines like this:
config.vm.define "jump", primary: true
config.vm.define "monitoring"`
config.vm.define "directory"
config.vm.define "master"
config.vm.define "db1"
config.vm.define "db2"
config.vm.define "mail"
config.vm.define "app1"
config.vm.define "app2"
config.vm.define "app3"
config.vm.define "app4"
config.vm.define "app5"
...I get twelve VMs which I can distinguish in Vagrant and using provider's tools, but with either the same default, box-provided hostname, or the same user-defined one, if not defined specifically. If i'd want to change the hostname, I'd need to specify the do…end block with *.vm.hostname inside, after each config.vm.define directive. Defining blocks using the same name twice or more times is typo-prone, which makes learning/development a bit more tedious (and I think we may agree that Vagrant is a nice tool for this, so we want Vagrantfiles to be as simple as they can.
Solution I'd see most useful
A kind of variable(s) or procedure(s), which may return values like actually processed VM name, as it happens with File.basename(Dir.getwd)], which I personally use to group VMs in VirtualBox. So, I'd like to define something like config.vm.hostname = "#{config.vm.name}" (or vb.name = "#{config.vm.name}", if config.vm.provider block is defined).
Alternatives I've considered
- It may be useful if the
config.vm.define, along with theprimaryorautostartvariables, would at least allow to include something likehostname = :automatic… - …or do something similar (reversed?) in case of
config.vm.hostname. - I am aware that I can define VMs in loops, using several arrays, but it's unintuitive workaround - neither for me, nor for someone who knows nothing about Vagrantfile structure or programming at all. Additionally, creating unneeded structures needs us to overcomplicate a simple solution unnecessarily.
Additional context
I've tried to search solution in Vagrant code, but I couldn't find anything useful, as I don't know Ruby. Therefore, I tried to continue here, after asking in two other places:
Other cases where I can use to simplify Vagrantfile's syntax is to conditionally define provisioning scripts based on VM names, if these scripts exist.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the config.vm.define and config.vm.hostname entry points in Vagrant's Ruby configuration flow; the issue does not name a source file or test. Define the desired automatic hostname behavior for each named machine, then verify it in a multimachine configuration and add coverage for the chosen interface.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- devops, infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100