github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/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 * `lower` - Lowercases the string. 57 * `pwd` - The working directory while executing Packer. 58 * `isotime [FORMAT]` - UTC time, which can be [formatted](http://golang.org/pkg/time/#example_Time_Format). 59 See more examples below. 60 * `timestamp` - The current Unix timestamp in UTC. 61 * `uuid` - Returns a random UUID. 62 * `upper` - Uppercases the string. 63 64 ### isotime Format 65 66 Formatting for the function `isotime` uses the magic reference date 67 **Mon Jan 2 15:04:05 -0700 MST 2006**, which breaks down to the following: 68 69 <table border="1" cellpadding="5" width="100%"> 70 <tr bgcolor="lightgray"> 71 <td></td> 72 <td align="center"><strong>Day of Week</strong></td> 73 <td align="center"><strong>Month</strong></td> 74 <td align="center"><strong>Date</strong></td> 75 <td align="center"><strong>Hour</strong></td> 76 <td align="center"><strong>Minute</strong></td> 77 <td align="center"><strong>Second</strong></td> 78 <td align="center"><strong>Year</strong></td> 79 <td align="center"><strong>Timezone</strong></td> 80 </tr> 81 <tr> 82 <td><strong>Numeric</strong></td> 83 <td align="center">-</td> 84 <td align="center">01</td> 85 <td align="center">02</td> 86 <td align="center">03 (15)</td> 87 <td align="center">04</td> 88 <td align="center">05</td> 89 <td align="center">06</td> 90 <td align="center">-0700</td> 91 </tr> 92 <tr> 93 <td><strong>Textual</strong></td> 94 <td align="center">Monday (Mon)</td> 95 <td align="center">January (Jan)</td> 96 <td align="center">-</td> 97 <td align="center">-</td> 98 <td align="center">-</td> 99 <td align="center">-</td> 100 <td align="center">-</td> 101 <td align="center">MST</td> 102 </tr> 103 </table> 104 105 _The values in parentheses are the abbreviated, or 24-hour clock values_ 106 107 Here are some example formated time, using the above format options: 108 109 <pre> 110 isotime = June 7, 7:22:43pm 2014 111 112 {{isotime "2006-01-02"}} = 2014-06-07 113 {{isotime "Mon 1506"}} = Sat 1914 114 {{isotime "01-Jan-06 03\_04\_05"}} = 07-Jun-2014 07\_22\_43 115 {{isotime "Hour15Year200603"}} = Hour19Year201407 116 </pre> 117 118 ## Amazon Specific Functions 119 120 Specific to Amazon builders: 121 122 * ``clean_ami_name`` - AMI names can only contain certain characters. This 123 function will replace illegal characters with a '-" character. Example usage 124 since ":" is not a legal AMI name is: `{{isotime | clean_ami_name}}`.