- `SourceAMIOwnerName` - The source AMI owner alias/name (for example `amazon`).
- `SourceAMITags` - The source AMI Tags, as a `map[string]string` object.
## Build Shared Information Variables
## Build function template engine variables
This builder generates data that are shared with provisioner and post-processor via build function of [template engine](/docs/templates/engine) for JSON and [contextual variables](/docs/from-1.5/contextual-variables) for HCL2.
The generated variables available for this builder are:
For the build function of [template engine](/docs/templates/engine), the following
variables are available:
- `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
- `SourceAMIOwnerName` - The source AMI owner alias/name (for example `amazon`).
- `SourceAMITags` - The source AMI Tags, as a `map[string]string` object.
## Build Shared Information Variables
## Build function template engine variables
This builder generates data that are shared with provisioner and post-processor via build function of [template engine](/docs/templates/engine) for JSON and [contextual variables](/docs/from-1.5/contextual-variables) for HCL2.
The generated variables available for this builder are:
For the build function of [template engine](/docs/templates/engine), the following
variables are available:
- `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
build the AMI.
Usage example:
<Tabs>
<Tab heading="JSON">
```json
"post-processors": [
{
"type": "manifest",
"output": "manifest.json",
"strip_path": true,
"custom_data": {
"source_ami_name": "{{ build `SourceAMIName` }}"
}
}
]
```
</Tab>
<Tab heading="HCL2">
```hcl
post-processor "manifest" {
output = "manifest.json"
strip_path = true
custom_data = {
source_ami_name = "${build.SourceAMIName}"
}
}
```
</Tab>
</Tabs>
## Tag Example
Here is an example using the optional AMI tags. This will add the tags
- `SourceAMIOwnerName` - The source AMI owner alias/name (for example `amazon`).
- `SourceAMITags` - The source AMI Tags, as a `map[string]string` object.
## Build Shared Information Variables
## Build function template engine variables
This builder generates data that are shared with provisioner and post-processor via build function of [template engine](/docs/templates/engine) for JSON and [contextual variables](/docs/from-1.5/contextual-variables) for HCL2.
The generated variables available for this builder are:
For the build function of [template engine](/docs/templates/engine), the following
variables are available:
- `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
build the AMI.
Usage example:
<Tabs>
<Tab heading="JSON">
```json
"post-processors": [
{
"type": "manifest",
"output": "manifest.json",
"strip_path": true,
"custom_data": {
"source_ami_name": "{{ build `SourceAMIName` }}"
}
}
]
```
</Tab>
<Tab heading="HCL2">
```hcl
post-processor "manifest" {
output = "manifest.json"
strip_path = true
custom_data = {
source_ami_name = "${build.SourceAMIName}"
}
}
```
</Tab>
</Tabs>
-> **Note:** Packer uses pre-built AMIs as the source for building images.
These source AMIs may include volumes that are not flagged to be destroyed on
termination of the instance building the new image. In addition to those
@ -243,48 +243,13 @@ termination of the instance building the new image. In addition to those
volumes created by this builder, any volumes in the source AMI which are not
marked for deletion on termination will remain in your account.
## Build Shared Information Variables
## Build function template engine variables
This builder generates data that are shared with provisioner and post-processor via build function of [template engine](/docs/templates/engine) for JSON and [contextual variables](/docs/from-1.5/contextual-variables) for HCL2.
The generated variables available for this builder are:
For the build function of [template engine](/docs/templates/engine), the following
variables are available:
- `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
- `SourceAMIOwnerName` - The source AMI owner alias/name (for example `amazon`).
- `SourceAMITags` - The source AMI Tags, as a `map[string]string` object.
## Build Shared Information Variables
## Build function template engine variables
This builder generates data that are shared with provisioner and post-processor via build function of [template engine](/docs/templates/engine) for JSON and [contextual variables](/docs/from-1.5/contextual-variables) for HCL2.
The generated variables available for this builder are:
For the build function of [template engine](/docs/templates/engine), the following
variables are available:
- `SourceAMIName` - The source AMI Name (for example
`ubuntu/images/ebs-ssd/ubuntu-xenial-16.04-amd64-server-20180306`) used to
build the AMI.
Usage example:
<Tabs>
<Tab heading="JSON">
```json
"post-processors": [
{
"type": "manifest",
"output": "manifest.json",
"strip_path": true,
"custom_data": {
"source_ami_name": "{{ build `SourceAMIName` }}"
}
}
]
```
</Tab>
<Tab heading="HCL2">
```hcl
post-processor "manifest" {
output = "manifest.json"
strip_path = true
custom_data = {
source_ami_name = "${build.SourceAMIName}"
}
}
```
</Tab>
</Tabs>
## Custom Bundle Commands
A lot of the process required for creating an instance-store backed AMI
The values within `only` or `except` are _source names_, not builder types.
## Build Contextual Variables
Packer allows to access connection information and basic instance state information from a post-processor. These information are stored in the `build` variable.
Check out the [Contextual Variables](/docs/from-1.5/contextual-variables) documentation to learn more about and see some examples of how to use them.
# This provisioner only runs for the 'first-example' source.
only = ["source.amazon-ebs.first-example"]
only = ["source.amazon-ebs.first-example"]
inline = [
"echo provisioning all the things",
@ -160,8 +160,3 @@ For the above provisioner, Packer will cancel the script if it takes more than
5 minutes.
Timeout has no effect in debug mode.
## Build Contextual Variables
Packer allows to access connection information and basic instance state information from a provisioner. These information are stored in the `build` variable.
Check out the [Contextual Variables](/docs/from-1.5/contextual-variables) documentation to learn more about and see some examples of how to use them.
- **ID**: Represents the vm being provisioned. For example, in Amazon it is the instance id; in digitalocean,
it is the droplet id; in Vmware, it is the vm name.
- **Host**, **Port**, **User** and **Password**: The host, port, user, and password that Packer uses to access the machine.
Useful for using the shell local provisioner to run Ansible or Inspec against the provisioned instance.
- **ConnType**: Type of communicator being used. For example, for SSH communicator this will be "ssh".
- **PackerRunUUID**: Current build's unique id. Can be used to specify build artifacts.
An example of that, is when multiple builds runs at the same time producing the same artifact.
It's possible to differentiate these artifacts by naming them with the builds' unique ids.
- **PackerHTTPIP**, **PackerHTTPPort**, and **PackerHTTPAddr**: HTTP IP, port, and address of the file server Packer creates to serve items in the "http" dir to the vm. The HTTP address is displayed in the format `IP:PORT`.
- **SSHPublicKey** and **SSHPrivateKey**: The public and private key that Packer uses to connect to the instance.
These are unique to the SSH communicator and are unset when using other communicators.
**SSHPublicKey** and **SSHPrivateKey** can have escape sequences and special characters so their output should be single quoted to avoid surprises. For example:
@ -83,8 +83,6 @@ Here is a full list of the available functions for reference.
- **ConnType**: Type of communicator being used. For example, for SSH communicator this will be "ssh".
- **PackerRunUUID**: Current build's unique id. Can be used to specify build artifacts.
An example of that, is when multiple builds runs at the same time producing the same artifact.
It's possible to differentiate these artifacts by naming them with the builds' unique ids.
- **PackerHTTPIP**, **PackerHTTPPort**, and **PackerHTTPAddr**: HTTP IP, port, and address of the file server Packer creates to serve items in the "http" dir to the vm. The HTTP address is displayed in the format `IP:PORT`.
@ -100,20 +98,16 @@ Here is a full list of the available functions for reference.
}
```
For backwards compatibility, `WinRMPassword` is also available through this
For backwards compatability, `WinRMPassword` is also available through this
engine, though it is no different than using the more general `Password`.
This function is only for use within specific options inside of
_provisioners_ -- these options will be listed as being template engines
in the provisioner documentation.
in the provisioner documentation. This feature does not yet work
if the provisioners are being used in conjunction with our chroot builders
or with lxc/lxd builders.
For builder-specific builder variables, please also refer to the builder docs: