Enhancement Request: Support multiple SSH configurations
- Dominant language
- Ruby
- Stars
- 27.2k
- Forks
- 4.4k
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
### Problem
Vagrantfile setting [config.ssh.private_key_path](https://developer.hashicorp.com/vagrant/docs/vagrantfile/ssh_settings#config-ssh-private_key_path) offers the possibility to specify multiple keys to try in turn. However, other `config.ssh` settings lack this feature.
This is inconvenient, because I install new users during VM provisioning (with Ansible) and delete the default user (usually `vagrant`). So I'd also want to try different values for other ssh settings, like `username`. This does not seem possible today.
### Proposed Solution
Ideally, Vagrant should accept an array of `ssh` configurations to try in turn. Could look like this in the Vagrantfile:
```
config.ssh = [
{
"username" => "joe",
"insert_key" => false,
"keys_only" => false
},
{
"username" => "vagrant",
"private_key_path" => "vagrant-default-key.pem",
"insert_key" => false
}
]
```
I guess there's a more rubyesque way to phrase the above.
Obviously, specifying just a single ssh configuration should still be possible without changes. Both for backwards compatibility and for convenience.
### Alternatives
I've worked around this problem by using a marker-file that my Ansible scripts create after provisioning custom users. In my Vagrant file I then use this:
```
if File.file?(".provisioned-marker")
config.ssh.username = "joe"
config.ssh.insert_key = false
config.ssh.keys_only = false
else
config.ssh.username = "vagrant"
config.ssh.private_key_path = "vagrant-default-key.pem"
config.ssh.insert_key = false
end
```
This works reasonable well for me, but it bloats my provisioning scripts.
Another alternative that I've considered:
Query Vagrants own provisioning state from within the Vagrant file. That is the same state that tells Vagrant whether to run provisioning upon `vagrant up`. But I haven't found a way to access this state programatically.
### Context
I've read to latest Vagrant docs online to see, if such feature already exists.
I've also done some testing with Vagrant 2.2.19 from Ubuntu 22.04.1 LTS.
If anyone finds the proposed feature useful, I might attempt a PR...
Contributor guide
Research direction
Start with the Vagrantfile config.ssh entry point and the SSH settings documentation linked in the issue. Review how the existing private_key_path list is handled and determine the compatibility and retry behavior for multiple SSH configurations. Done means single configurations still work and multiple configurations are tried in order for the requested settings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- cli, infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100