Add winrm functionality to null provisioner (#2525)
* Add new functions to communicator helper to return the user, password, host, based on the communicator used. This implementation can help then generalize the provisioeners later on. * Update null builder checks to utilize the new functions and check for ANY hostname or user or password * Update builder to user any hostname
This commit is contained in:
parent
dca2b515a3
commit
9c9f8cd451
|
@ -30,7 +30,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
steps := []multistep.Step{
|
steps := []multistep.Step{
|
||||||
&communicator.StepConnect{
|
&communicator.StepConnect{
|
||||||
Config: &b.config.CommConfig,
|
Config: &b.config.CommConfig,
|
||||||
Host: CommHost(b.config.CommConfig.SSHHost),
|
Host: CommHost(b.config.CommConfig.Host()),
|
||||||
SSHConfig: SSHConfig(
|
SSHConfig: SSHConfig(
|
||||||
b.config.CommConfig.SSHUsername,
|
b.config.CommConfig.SSHUsername,
|
||||||
b.config.CommConfig.SSHPassword,
|
b.config.CommConfig.SSHPassword,
|
||||||
|
|
|
@ -31,19 +31,19 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
if es := c.CommConfig.Prepare(nil); len(es) > 0 {
|
if es := c.CommConfig.Prepare(nil); len(es) > 0 {
|
||||||
errs = packer.MultiErrorAppend(errs, es...)
|
errs = packer.MultiErrorAppend(errs, es...)
|
||||||
}
|
}
|
||||||
if c.CommConfig.SSHHost == "" {
|
if c.CommConfig.Host() == "" {
|
||||||
errs = packer.MultiErrorAppend(errs,
|
errs = packer.MultiErrorAppend(errs,
|
||||||
fmt.Errorf("ssh_host must be specified"))
|
fmt.Errorf("a Host must be specified, please reference your communicator documentation"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.CommConfig.SSHUsername == "" {
|
if c.CommConfig.User() == "" {
|
||||||
errs = packer.MultiErrorAppend(errs,
|
errs = packer.MultiErrorAppend(errs,
|
||||||
fmt.Errorf("ssh_username must be specified"))
|
fmt.Errorf("a Username must be specified, please reference your communicator documentation"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.CommConfig.SSHPassword == "" && c.CommConfig.SSHPrivateKey == "" {
|
if c.CommConfig.Password() == "" && c.CommConfig.SSHPrivateKey == "" {
|
||||||
errs = packer.MultiErrorAppend(errs,
|
errs = packer.MultiErrorAppend(errs,
|
||||||
fmt.Errorf("one of ssh_password and ssh_private_key_file must be specified"))
|
fmt.Errorf("one authentication method must be specified, please reference your communicator documentation"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.CommConfig.SSHPassword != "" && c.CommConfig.SSHPrivateKey != "" {
|
if c.CommConfig.SSHPassword != "" && c.CommConfig.SSHPrivateKey != "" {
|
||||||
|
|
|
@ -55,6 +55,42 @@ func (c *Config) Port() int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Host returns the port that will be used for access based on config.
|
||||||
|
func (c *Config) Host() string {
|
||||||
|
switch c.Type {
|
||||||
|
case "ssh":
|
||||||
|
return c.SSHHost
|
||||||
|
case "winrm":
|
||||||
|
return c.WinRMHost
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// User returns the port that will be used for access based on config.
|
||||||
|
func (c *Config) User() string {
|
||||||
|
switch c.Type {
|
||||||
|
case "ssh":
|
||||||
|
return c.SSHUsername
|
||||||
|
case "winrm":
|
||||||
|
return c.WinRMUser
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Password returns the port that will be used for access based on config.
|
||||||
|
func (c *Config) Password() string {
|
||||||
|
switch c.Type {
|
||||||
|
case "ssh":
|
||||||
|
return c.SSHPassword
|
||||||
|
case "winrm":
|
||||||
|
return c.WinRMPassword
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Config) Prepare(ctx *interpolate.Context) []error {
|
func (c *Config) Prepare(ctx *interpolate.Context) []error {
|
||||||
if c.Type == "" {
|
if c.Type == "" {
|
||||||
c.Type = "ssh"
|
c.Type = "ssh"
|
||||||
|
|
Loading…
Reference in New Issue