2013-06-10 18:08:14 -04:00
|
|
|
---
|
|
|
|
layout: "docs"
|
|
|
|
---
|
|
|
|
|
|
|
|
# Configuration Templates
|
|
|
|
|
2013-08-08 19:56:09 -04:00
|
|
|
All strings within templates are processed by a common Packer templating
|
|
|
|
engine, where variables and functions can be used to modify the value of
|
|
|
|
a configuration parameter at runtime.
|
|
|
|
|
|
|
|
For example, the `{{timestamp}}` function can be used in any string to
|
|
|
|
generate the current timestamp. This is useful for configurations that require
|
|
|
|
unique keys, such as AMI names. By setting the AMI name to something like
|
|
|
|
`My Packer AMI {{timestamp}}`, the AMI name will be unique down to the second.
|
|
|
|
|
|
|
|
In addition to globally available functions like timestamp shown before,
|
|
|
|
some configurations have special local variables that are available only
|
|
|
|
for that configuration. These are recognizable because they're prefixed by
|
|
|
|
a period, such as `{{.Name}}`.
|
|
|
|
|
|
|
|
The complete syntax is covered in the next section, followed by a reference
|
|
|
|
of globally available functions.
|
2013-06-10 18:08:14 -04:00
|
|
|
|
|
|
|
## Syntax
|
|
|
|
|
2013-08-08 19:56:09 -04:00
|
|
|
The syntax of templates is extremely simple. Anything template related
|
|
|
|
happens within double-braces: `{{ }}`. Variables are prefixed with a period
|
|
|
|
and capitalized, such as `{{.Variable}}` and functions are just directly
|
|
|
|
within the braces, such as `{{timestamp}}`.
|
|
|
|
|
|
|
|
Here is an example from the VMware VMX template that shows configuration
|
|
|
|
templates in action:
|
2013-06-10 18:08:14 -04:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
.encoding = "UTF-8"
|
|
|
|
displayName = "{{ .Name }}"
|
|
|
|
guestOS = "{{ .GuestOS }}"
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
In this case, the "Name" and "GuestOS" variables will be replaced, potentially
|
|
|
|
resulting in a VMX that looks like this:
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
.encoding = "UTF-8"
|
|
|
|
displayName = "packer"
|
|
|
|
guestOS = "otherlinux"
|
|
|
|
</pre>
|
2013-08-08 19:56:09 -04:00
|
|
|
|
|
|
|
## Global Functions
|
|
|
|
|
|
|
|
While some configuration settings have local variables specific to only that
|
|
|
|
configuration, a set of functions are available globally for use in _any string_
|
|
|
|
in Packer templates. These are listed below for reference.
|
|
|
|
|
|
|
|
* ``timestamp`` - The current Unix timestamp in UTC.
|