website: new config template docs
This commit is contained in:
parent
1b01e82d8d
commit
16ccfe3824
|
@ -4,34 +4,32 @@ layout: "docs"
|
||||||
|
|
||||||
# Configuration Templates
|
# Configuration Templates
|
||||||
|
|
||||||
Certain configuration parameters within templates are themselves a
|
All strings within templates are processed by a common Packer templating
|
||||||
type of "template." These are not Packer templates, but text templates,
|
engine, where variables and functions can be used to modify the value of
|
||||||
where variables can be used to modify the value of a configuration parameter
|
a configuration parameter at runtime.
|
||||||
during runtime.
|
|
||||||
|
|
||||||
For example, the `ami_name` configuration for the [AMI builder](/docs/builders/amazon-ebs.html)
|
For example, the `{{timestamp}}` function can be used in any string to
|
||||||
is a template. An example value may be `My Packer AMI {{.CreateTime}}`. At
|
generate the current timestamp. This is useful for configurations that require
|
||||||
runtime, this will be turned into `My Packer AMI 1370900368`, where the
|
unique keys, such as AMI names. By setting the AMI name to something like
|
||||||
"CreateTime" variable was replaced with the Unix timestamp of when the
|
`My Packer AMI {{timestamp}}`, the AMI name will be unique down to the second.
|
||||||
AMI was actually created.
|
|
||||||
|
|
||||||
This sort of templating is pervasive throughout Packer. Instead of documenting
|
In addition to globally available functions like timestamp shown before,
|
||||||
the templating syntax in each location, it is documented once here so
|
some configurations have special local variables that are available only
|
||||||
you know how to use it.
|
for that configuration. These are recognizable because they're prefixed by
|
||||||
|
a period, such as `{{.Name}}`.
|
||||||
|
|
||||||
<div class="alert alert-info">
|
The complete syntax is covered in the next section, followed by a reference
|
||||||
<strong>For advanced users:</strong> The templates are actually parsed and executed
|
of globally available functions.
|
||||||
using Go's <a href="http://golang.org/pkg/text/template/">text/template</a>
|
|
||||||
package. It therefore supports the complete template syntax.
|
|
||||||
</div>
|
|
||||||
|
|
||||||
## Syntax
|
## Syntax
|
||||||
|
|
||||||
99% of the time all you'll need within configuration templates are variables.
|
The syntax of templates is extremely simple. Anything template related
|
||||||
Variables are accessed by using `{{.VARIABLENAME}}`. The "." prefixing the
|
happens within double-braces: `{{ }}`. Variables are prefixed with a period
|
||||||
variable name signals that you're accessing a variable on the root
|
and capitalized, such as `{{.Variable}}` and functions are just directly
|
||||||
template object. All template directives go between braces. Here is a piece
|
within the braces, such as `{{timestamp}}`.
|
||||||
of a VMware VMX template that uses variables:
|
|
||||||
|
Here is an example from the VMware VMX template that shows configuration
|
||||||
|
templates in action:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
.encoding = "UTF-8"
|
.encoding = "UTF-8"
|
||||||
|
@ -47,3 +45,11 @@ resulting in a VMX that looks like this:
|
||||||
displayName = "packer"
|
displayName = "packer"
|
||||||
guestOS = "otherlinux"
|
guestOS = "otherlinux"
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
Loading…
Reference in New Issue