github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/website/source/docs/templates/configuration-templates.html.markdown (about) 1 --- 2 layout: "docs" 3 page_title: "Configuration Templates" 4 --- 5 6 # Configuration Templates 7 8 All strings within templates are processed by a common Packer templating 9 engine, where variables and functions can be used to modify the value of 10 a configuration parameter at runtime. 11 12 For example, the `{{timestamp}}` function can be used in any string to 13 generate the current timestamp. This is useful for configurations that require 14 unique keys, such as AMI names. By setting the AMI name to something like 15 `My Packer AMI {{timestamp}}`, the AMI name will be unique down to the second. 16 17 In addition to globally available functions like timestamp shown before, 18 some configurations have special local variables that are available only 19 for that configuration. These are recognizable because they're prefixed by 20 a period, such as `{{.Name}}`. 21 22 The complete syntax is covered in the next section, followed by a reference 23 of globally available functions. 24 25 ## Syntax 26 27 The syntax of templates is extremely simple. Anything template related 28 happens within double-braces: `{{ }}`. Variables are prefixed with a period 29 and capitalized, such as `{{.Variable}}` and functions are just directly 30 within the braces, such as `{{timestamp}}`. 31 32 Here is an example from the VMware VMX template that shows configuration 33 templates in action: 34 35 <pre> 36 .encoding = "UTF-8" 37 displayName = "{{ .Name }}" 38 guestOS = "{{ .GuestOS }}" 39 </pre> 40 41 In this case, the "Name" and "GuestOS" variables will be replaced, potentially 42 resulting in a VMX that looks like this: 43 44 <pre> 45 .encoding = "UTF-8" 46 displayName = "packer" 47 guestOS = "otherlinux" 48 </pre> 49 50 ## Global Functions 51 52 While some configuration settings have local variables specific to only that 53 configuration, a set of functions are available globally for use in _any string_ 54 in Packer templates. These are listed below for reference. 55 56 * ``timestamp`` - The current Unix timestamp in UTC.