Merge pull request #7782 from hashicorp/fix_7758

Allow user to override vagrant ssh-config details
This commit is contained in:
Megan Marsh 2019-06-25 09:18:24 -07:00 committed by GitHub
commit bed0938b6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 5 deletions

View File

@ -36,8 +36,6 @@ func (s *StepSSHConfig) Run(ctx context.Context, state multistep.StateBag) multi
return multistep.ActionHalt
}
config.Comm.SSHPrivateKeyFile = sshConfig.IdentityFile
config.Comm.SSHUsername = sshConfig.User
config.Comm.SSHHost = sshConfig.Hostname
port, err := strconv.Atoi(sshConfig.Port)
if err != nil {
@ -46,6 +44,14 @@ func (s *StepSSHConfig) Run(ctx context.Context, state multistep.StateBag) multi
}
config.Comm.SSHPort = port
if config.Comm.SSHUsername != "" {
// If user has set the username within the communicator, use the
// auth provided there.
return multistep.ActionContinue
}
config.Comm.SSHPrivateKeyFile = sshConfig.IdentityFile
config.Comm.SSHUsername = sshConfig.User
return multistep.ActionContinue
}

View File

@ -62,7 +62,7 @@ one, by using `global_id` instead of `source_box`.
"packer_" plus your buildname.
- `provider` (string) - The vagrant [provider](docs/post-processors/vagrant.html).
This parameter is required when `source_path` have more than one provider,
This parameter is required when `source_path` have more than one provider,
or when using `vagrant-cloud` post-processor. Defaults to unset.
- `checksum` (string) - The checksum for the .box file. The type of the
@ -127,11 +127,11 @@ one, by using `global_id` instead of `source_box`.
package your base box into its own standalone .box file.
- `output_vagrantfile` (string) - Equivalent to setting the
[`--vagrantfile`](https://www.vagrantup.com/docs/cli/package.html#vagrantfile-file) option
[`--vagrantfile`](https://www.vagrantup.com/docs/cli/package.html#vagrantfile-file) option
in `vagrant package`; defaults to unset
- `package_include` (string) - Equivalent to setting the
[`--include`](https://www.vagrantup.com/docs/cli/package.html#include-x-y-z) option
[`--include`](https://www.vagrantup.com/docs/cli/package.html#include-x-y-z) option
in `vagrant package`; defaults to unset
## Example
@ -151,3 +151,19 @@ Sample for `hashicorp/precise64` with virtualbox provider.
]
}
```
## A note on SSH connections
Currently this builder only works for SSH connections, and automatically fills
in all information needed for the ssh communicator using vagrant's ssh-config.
If you would like to connect via a different username or authentication method
than is produced when you call `vagrant ssh-config`, then you must provide the
`ssh_username` and all other relevant authentication information (e.g.
`ssh_password` or `ssh_private_key_file`)
By providing the `ssh_username`, you're telling Packer not to use the vagrant
ssh config, except for determining the host and port for the virtual machine to
connect to.