Merge pull request #7940 from jgeorgeson/openstack-winrmpassword-provisioners

OpenStack builder store WinRM password for provisioners to use
This commit is contained in:
Megan Marsh 2019-08-15 12:02:26 -07:00 committed by GitHub
commit 94d8da60f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 22 deletions

View File

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
commonhelper "github.com/hashicorp/packer/helper/common"
"github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
@ -19,6 +20,7 @@ import (
type StepGetPassword struct { type StepGetPassword struct {
Debug bool Debug bool
Comm *communicator.Config Comm *communicator.Config
BuildName string
} }
func (s *StepGetPassword) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepGetPassword) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
@ -76,7 +78,12 @@ func (s *StepGetPassword) Run(ctx context.Context, state multistep.StateBag) mul
"Password (since debug is enabled) \"%s\"", s.Comm.WinRMPassword)) "Password (since debug is enabled) \"%s\"", s.Comm.WinRMPassword))
} }
commonhelper.SetSharedState("winrm_password", s.Comm.WinRMPassword, s.BuildName)
packer.LogSecretFilter.Set(s.Comm.WinRMPassword)
return multistep.ActionContinue return multistep.ActionContinue
} }
func (s *StepGetPassword) Cleanup(multistep.StateBag) {} func (s *StepGetPassword) Cleanup(multistep.StateBag) {
commonhelper.RemoveSharedStateFile("winrm_password", s.BuildName)
}

View File

@ -60,8 +60,8 @@ Optional Parameters:
"ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False", "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s'", "ANSIBLE_NOCOLOR=True" ] "ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False", "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s'", "ANSIBLE_NOCOLOR=True" ]
``` ```
If you are running a Windows build on AWS, Azure or Google Compute and If you are running a Windows build on AWS, Azure, Google Compute, or OpenStack
would like to access the auto-generated password that Packer uses to and would like to access the auto-generated password that Packer uses to
connect to a Windows instance via WinRM, you can use the template variable connect to a Windows instance via WinRM, you can use the template variable
{{.WinRMPassword}} in this option. For example: {{.WinRMPassword}} in this option. For example:
@ -85,8 +85,8 @@ Optional Parameters:
"extra_arguments": [ "--extra-vars", "Region={{user `Region`}} Stage={{user `Stage`}}" ] "extra_arguments": [ "--extra-vars", "Region={{user `Region`}} Stage={{user `Stage`}}" ]
``` ```
If you are running a Windows build on AWS, Azure or Google Compute and If you are running a Windows build on AWS, Azure, Google Compute, or OpenStack
would like to access the auto-generated password that Packer uses to and would like to access the auto-generated password that Packer uses to
connect to a Windows instance via WinRM, you can use the template variable connect to a Windows instance via WinRM, you can use the template variable
{{.WinRMPassword}} in this option. For example: {{.WinRMPassword}} in this option. For example:

View File

@ -50,8 +50,8 @@ The example below is fully functional.
inject prior to the execute\_command. The format should be `key=value`. inject prior to the execute\_command. The format should be `key=value`.
Packer injects some environmental variables by default into the Packer injects some environmental variables by default into the
environment, as well, which are covered in the section below. If you are environment, as well, which are covered in the section below. If you are
running on AWS, Azure or Google Compute and would like to access the running on AWS, Azure, Google Compute, or OpenStack and would like to access
generated password that Packer uses to connect to the instance via WinRM, the generated password that Packer uses to connect to the instance via WinRM,
you can use the template variable `{{.WinRMPassword}}` to set this as an you can use the template variable `{{.WinRMPassword}}` to set this as an
environment variable. For example: environment variable. For example:
@ -84,9 +84,9 @@ The example below is fully functional.
- `elevated_user` and `elevated_password` (string) - If specified, the - `elevated_user` and `elevated_password` (string) - If specified, the
PowerShell script will be run with elevated privileges using the given PowerShell script will be run with elevated privileges using the given
Windows user. If you are running a build on AWS, Azure or Google Compute Windows user. If you are running a build on AWS, Azure, Google Compute,
and would like to run using the generated password that Packer uses to or OpenStack and would like to run using the generated password that Packer
connect to the instance via WinRM, you may do so by using the template uses to connect to the instance via WinRM, you may do so by using the template
variable {{.WinRMPassword}}. For example: variable {{.WinRMPassword}}. For example:
``` json ``` json

View File

@ -41,9 +41,9 @@ Exactly *one* of the following is required:
- `command` (string) - This is a single command to execute. It will be - `command` (string) - This is a single command to execute. It will be
written to a temporary file and run using the `execute_command` call below. written to a temporary file and run using the `execute_command` call below.
If you are building a windows vm on AWS, Azure or Google Compute and would If you are building a windows vm on AWS, Azure, Google Compute, or OpenStack
like to access the generated password that Packer uses to connect to the and would like to access the generated password that Packer uses to connect
instance via WinRM, you can use the template variable `{{.WinRMPassword}}` to the instance via WinRM, you can use the template variable `{{.WinRMPassword}}`
to set this as an environment variable. to set this as an environment variable.
- `inline` (array of strings) - This is an array of commands to execute. The - `inline` (array of strings) - This is an array of commands to execute. The
@ -68,10 +68,10 @@ Optional parameters:
inject prior to the `execute_command`. The format should be `key=value`. inject prior to the `execute_command`. The format should be `key=value`.
Packer injects some environmental variables by default into the Packer injects some environmental variables by default into the
environment, as well, which are covered in the section below. If you are environment, as well, which are covered in the section below. If you are
building a windows vm on AWS, Azure or Google Compute and would like to building a windows vm on AWS, Azure, Google Compute, or OpenStack and would
access the generated password that Packer uses to connect to the instance like to access the generated password that Packer uses to connect to the
via WinRM, you can use the template variable `{{.WinRMPassword}}` to set instance via WinRM, you can use the template variable `{{.WinRMPassword}}`
this as an environment variable. For example: to set this as an environment variable. For example:
`"environment_vars": "WINRMPASS={{.WinRMPassword}}"` `"environment_vars": "WINRMPASS={{.WinRMPassword}}"`
- `env_var_format` (string) - When we parse the environment\_vars that you - `env_var_format` (string) - When we parse the environment\_vars that you
@ -103,9 +103,9 @@ Optional parameters:
sake of clarity, as even when you set only a single `command` to run, sake of clarity, as even when you set only a single `command` to run,
Packer writes it to a temporary file and then runs it as a script. Packer writes it to a temporary file and then runs it as a script.
If you are building a windows vm on AWS, Azure or Google Compute and would If you are building a windows vm on AWS, Azure, Google Compute, or OpenStack
like to access the generated password that Packer uses to connect to the and would like to access the generated password that Packer uses to connect
instance via WinRM, you can use the template variable `{{.WinRMPassword}}` to the instance via WinRM, you can use the template variable `{{.WinRMPassword}}`
to set this as an environment variable. to set this as an environment variable.
- `inline_shebang` (string) - The - `inline_shebang` (string) - The