ansible-local/ansible: Add extra-vars packer_*
Added: - `packer_build_name` - `packer_builder_type` - `packer_http_addr` - `ansible-local` only Closes: #4820
This commit is contained in:
parent
3608d81319
commit
999f2da499
|
@ -294,9 +294,10 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator) err
|
|||
playbook := filepath.ToSlash(filepath.Join(p.config.StagingDir, filepath.Base(p.config.PlaybookFile)))
|
||||
inventory := filepath.ToSlash(filepath.Join(p.config.StagingDir, filepath.Base(p.config.InventoryFile)))
|
||||
|
||||
extraArgs := ""
|
||||
extraArgs := fmt.Sprintf(" --extra-vars \"packer_build_name=%s packer_builder_type=%s packer_http_addr=%s\" ",
|
||||
p.config.PackerBuildName, p.config.PackerBuilderType, common.GetHTTPAddr())
|
||||
if len(p.config.ExtraArguments) > 0 {
|
||||
extraArgs = " " + strings.Join(p.config.ExtraArguments, " ")
|
||||
extraArgs = extraArgs + strings.Join(p.config.ExtraArguments, " ")
|
||||
}
|
||||
|
||||
// Fetch external dependencies
|
||||
|
|
|
@ -305,7 +305,9 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator, pri
|
|||
inventory := p.config.inventoryFile
|
||||
var envvars []string
|
||||
|
||||
args := []string{playbook, "-i", inventory}
|
||||
args := []string{"--extra-vars", fmt.Sprintf("packer_build_name=%s packer_builder_type=%s",
|
||||
p.config.PackerBuildName, p.config.PackerBuilderType),
|
||||
"-i", inventory, playbook}
|
||||
if len(privKeyFile) > 0 {
|
||||
args = append(args, "--private-key", privKeyFile)
|
||||
}
|
||||
|
@ -354,7 +356,7 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator, pri
|
|||
go repeat(stdout)
|
||||
go repeat(stderr)
|
||||
|
||||
log.Printf("Executing Ansible: %s", strings.Join(cmd.Args, " "))
|
||||
ui.Say(fmt.Sprintf("Executing Ansible: %s", strings.Join(cmd.Args, " ")))
|
||||
if err := cmd.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -136,3 +136,24 @@ chi-appservers
|
|||
able to create directories and write into this folder. If the permissions
|
||||
are not correct, use a shell provisioner prior to this to configure it
|
||||
properly.
|
||||
|
||||
## Default Extra Variables
|
||||
|
||||
In addition to being able to specify extra arguments using the
|
||||
`extra_arguments` configuration, the provisioner automatically defines certain
|
||||
commonly useful Ansible variables:
|
||||
|
||||
- `packer_build_name` is set to the name of the build that Packer is running.
|
||||
This is most useful when Packer is making multiple builds and you want to
|
||||
distinguish them slightly when using a common playbook.
|
||||
|
||||
- `packer_builder_type` is the type of the builder that was used to create the
|
||||
machine that the script is running on. This is useful if you want to run
|
||||
only certain parts of the playbook on systems built with certain builders.
|
||||
|
||||
- `packer_http_addr` If using a builder that provides an http server for file
|
||||
transfer (such as hyperv, parallels, qemu, virtualbox, and vmware), this
|
||||
will be set to the address. You can use this address in your provisioner to
|
||||
download large files over http. This may be useful if you're experiencing
|
||||
slower speeds using the default file provisioner. A file provisioner using
|
||||
the `winrm` communicator may experience these types of difficulties.
|
||||
|
|
|
@ -113,6 +113,22 @@ Optional Parameters:
|
|||
- `user` (string) - The `ansible_user` to use. Defaults to the user running
|
||||
packer.
|
||||
|
||||
|
||||
## Default Extra Variables
|
||||
|
||||
In addition to being able to specify extra arguments using the
|
||||
`extra_arguments` configuration, the provisioner automatically defines certain
|
||||
commonly useful Ansible variables:
|
||||
|
||||
- `packer_build_name` is set to the name of the build that Packer is running.
|
||||
This is most useful when Packer is making multiple builds and you want to
|
||||
distinguish them slightly when using a common playbook.
|
||||
|
||||
- `packer_builder_type` is the type of the builder that was used to create the
|
||||
machine that the script is running on. This is useful if you want to run
|
||||
only certain parts of the playbook on systems built with certain builders.
|
||||
|
||||
|
||||
## Limitations
|
||||
|
||||
### Redhat / CentOS
|
||||
|
|
Loading…
Reference in New Issue