Merge pull request #7137 from YuSungDuk/fix_to_get_ssh_password
Fix to get ssh password
This commit is contained in:
commit
7132037faa
|
@ -44,7 +44,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
NewStepCreateLoginKey(conn, ui),
|
||||
NewStepCreateServerInstance(conn, ui, b.config),
|
||||
NewStepCreateBlockStorageInstance(conn, ui, b.config),
|
||||
NewStepGetRootPassword(conn, ui),
|
||||
NewStepGetRootPassword(conn, ui, b.config),
|
||||
NewStepCreatePublicIPInstance(conn, ui, b.config),
|
||||
&communicator.StepConnectSSH{
|
||||
Config: &b.config.Comm,
|
||||
|
@ -68,7 +68,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
NewStepCreateLoginKey(conn, ui),
|
||||
NewStepCreateServerInstance(conn, ui, b.config),
|
||||
NewStepCreateBlockStorageInstance(conn, ui, b.config),
|
||||
NewStepGetRootPassword(conn, ui),
|
||||
NewStepGetRootPassword(conn, ui, b.config),
|
||||
NewStepCreatePublicIPInstance(conn, ui, b.config),
|
||||
&communicator.StepConnectWinRM{
|
||||
Config: &b.config.Comm,
|
||||
|
@ -78,7 +78,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
WinRMConfig: func(state multistep.StateBag) (*communicator.WinRMConfig, error) {
|
||||
return &communicator.WinRMConfig{
|
||||
Username: b.config.Comm.WinRMUser,
|
||||
Password: state.Get("Password").(string),
|
||||
Password: b.config.Comm.WinRMPassword,
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
|
|
|
@ -105,7 +105,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|||
errs = packer.MultiErrorAppend(errs, errors.New("If user_data field is set, length of UserData should be max 21847"))
|
||||
}
|
||||
|
||||
if c.Comm.Type == "wrinrm" && c.AccessControlGroupConfigurationNo == "" {
|
||||
if c.Comm.Type == "winrm" && c.AccessControlGroupConfigurationNo == "" {
|
||||
errs = packer.MultiErrorAppend(errs, errors.New("If Communicator is winrm, access_control_group_configuration_no is required"))
|
||||
}
|
||||
|
||||
|
|
|
@ -14,13 +14,15 @@ type StepGetRootPassword struct {
|
|||
GetRootPassword func(serverInstanceNo string, privateKey string) (string, error)
|
||||
Say func(message string)
|
||||
Error func(e error)
|
||||
Config *Config
|
||||
}
|
||||
|
||||
func NewStepGetRootPassword(conn *ncloud.Conn, ui packer.Ui) *StepGetRootPassword {
|
||||
func NewStepGetRootPassword(conn *ncloud.Conn, ui packer.Ui, config *Config) *StepGetRootPassword {
|
||||
var step = &StepGetRootPassword{
|
||||
Conn: conn,
|
||||
Say: func(message string) { ui.Say(message) },
|
||||
Error: func(e error) { ui.Error(e.Error()) },
|
||||
Conn: conn,
|
||||
Say: func(message string) { ui.Say(message) },
|
||||
Error: func(e error) { ui.Error(e.Error()) },
|
||||
Config: config,
|
||||
}
|
||||
|
||||
step.GetRootPassword = step.getRootPassword
|
||||
|
@ -51,7 +53,11 @@ func (s *StepGetRootPassword) Run(_ context.Context, state multistep.StateBag) m
|
|||
|
||||
rootPassword, err := s.GetRootPassword(serverInstanceNo, loginKey.PrivateKey)
|
||||
|
||||
state.Put("Password", rootPassword)
|
||||
if s.Config.Comm.Type == "ssh" {
|
||||
s.Config.Comm.SSHPassword = rootPassword
|
||||
} else if s.Config.Comm.Type == "winrm" {
|
||||
s.Config.Comm.WinRMPassword = rootPassword
|
||||
}
|
||||
|
||||
return processStepResult(err, s.Error, state)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ func TestStepGetRootPasswordShouldFailIfOperationGetRootPasswordFails(t *testing
|
|||
GetRootPassword: func(string, string) (string, error) { return "", fmt.Errorf("!! Unit Test FAIL !!") },
|
||||
Say: func(message string) {},
|
||||
Error: func(e error) {},
|
||||
Config: &Config{},
|
||||
}
|
||||
|
||||
stateBag := DeleteTestStateBagStepGetRootPassword()
|
||||
|
@ -33,6 +34,7 @@ func TestStepGetRootPasswordShouldPassIfOperationGetRootPasswordPasses(t *testin
|
|||
GetRootPassword: func(string, string) (string, error) { return "a", nil },
|
||||
Say: func(message string) {},
|
||||
Error: func(e error) {},
|
||||
Config: &Config{},
|
||||
}
|
||||
|
||||
stateBag := DeleteTestStateBagStepGetRootPassword()
|
||||
|
|
|
@ -64,6 +64,8 @@ Platform](https://www.ncloud.com/).
|
|||
|
||||
## Sample code of template.json
|
||||
|
||||
Here is a basic example for windows server.
|
||||
|
||||
{
|
||||
"variables": {
|
||||
"ncloud_access_key": "FRxhOQRNjKVMqIz3sRLY",
|
||||
|
@ -75,13 +77,40 @@ Platform](https://www.ncloud.com/).
|
|||
"access_key": "{{user `ncloud_access_key`}}",
|
||||
"secret_key": "{{user `ncloud_secret_key`}}",
|
||||
|
||||
"server_image_product_code": "SPSW0WINNT000016",
|
||||
"server_product_code": "SPSVRSSD00000011",
|
||||
"member_server_image_no": "4223",
|
||||
"server_image_product_code": "SPSW0WINNTEN0016",
|
||||
"server_product_code": "SPSVRSSD00000002",
|
||||
"server_image_name": "packer-test {{timestamp}}",
|
||||
"server_description": "server description",
|
||||
"server_image_description": "server description",
|
||||
"user_data": "CreateObject(\"WScript.Shell\").run(\"cmd.exe /c powershell Set-ExecutionPolicy RemoteSigned & winrm quickconfig -q & sc config WinRM start= auto & winrm set winrm/config/service/auth @{Basic=\"\"true\"\"} & winrm set winrm/config/service @{AllowUnencrypted=\"\"true\"\"} & winrm get winrm/config/service\")",
|
||||
"region": "US-West"
|
||||
"region": "US-West",
|
||||
"communicator": "winrm",
|
||||
"winrm_username": "Administrator",
|
||||
"access_control_group_configuration_no" : 4964
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Here is a basic example for linux server.
|
||||
|
||||
{
|
||||
"variables": {
|
||||
"ncloud_access_key": "FRxhOQRNjKVMqIz3sRLY",
|
||||
"ncloud_secret_key": "xd6kTO5iNcLookBx0D8TDKmpLj2ikxqEhc06MQD2"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
"type": "ncloud",
|
||||
"access_key": "{{user `ncloud_access_key`}}",
|
||||
"secret_key": "{{user `ncloud_secret_key`}}",
|
||||
|
||||
"server_image_product_code": "SPSW0LINUX000044",
|
||||
"server_product_code": "SPSVRSSD00000002",
|
||||
"server_image_name": "packertest2",
|
||||
"server_image_description": "server image description",
|
||||
"region": "US-West",
|
||||
"communicator": "ssh",
|
||||
"ssh_username": "root"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue