github.com/aclaygray/packer@v1.3.2/website/source/docs/templates/index.html.md (about) 1 --- 2 description: | 3 Templates are JSON files that configure the various components of Packer in 4 order to create one or more machine images. Templates are portable, static, 5 and readable and writable by both humans and computers. This has the added 6 benefit of being able to not only create and modify templates by hand, but 7 also write scripts to dynamically create or modify templates. 8 layout: docs 9 page_title: Templates 10 sidebar_current: 'docs-templates' 11 --- 12 13 # Templates 14 15 Templates are JSON files that configure the various components of Packer in 16 order to create one or more machine images. Templates are portable, static, and 17 readable and writable by both humans and computers. This has the added benefit 18 of being able to not only create and modify templates by hand, but also write 19 scripts to dynamically create or modify templates. 20 21 Templates are given to commands such as `packer build`, which will take the 22 template and actually run the builds within it, producing any resulting machine 23 images. 24 25 ## Template Structure 26 27 A template is a JSON object that has a set of keys configuring various 28 components of Packer. The available keys within a template are listed below. 29 Along with each key, it is noted whether it is required or not. 30 31 - `builders` (*required*) is an array of one or more objects that defines the 32 builders that will be used to create machine images for this template, and 33 configures each of those builders. For more information on how to define and 34 configure a builder, read the sub-section on [configuring builders in 35 templates](/docs/templates/builders.html). 36 37 - `description` (optional) is a string providing a description of what the 38 template does. This output is used only in the [inspect 39 command](/docs/commands/inspect.html). 40 41 - `min_packer_version` (optional) is a string that has a minimum Packer 42 version that is required to parse the template. This can be used to ensure 43 that proper versions of Packer are used with the template. A max version 44 can't be specified because Packer retains backwards compatibility with 45 `packer fix`. 46 47 - `post-processors` (optional) is an array of one or more objects that defines 48 the various post-processing steps to take with the built images. If not 49 specified, then no post-processing will be done. For more information on 50 what post-processors do and how they're defined, read the sub-section on 51 [configuring post-processors in 52 templates](/docs/templates/post-processors.html). 53 54 - `provisioners` (optional) is an array of one or more objects that defines 55 the provisioners that will be used to install and configure software for the 56 machines created by each of the builders. If it is not specified, then no 57 provisioners will be run. For more information on how to define and 58 configure a provisioner, read the sub-section on [configuring provisioners 59 in templates](/docs/templates/provisioners.html). 60 61 - `variables` (optional) is an object of one or more key/value strings that 62 defines user variables contained in the template. If it is not specified, 63 then no variables are defined. For more information on how to define and use 64 user variables, read the sub-section on [user variables in 65 templates](/docs/templates/user-variables.html). 66 67 ## Comments 68 69 JSON doesn't support comments and Packer reports unknown keys as validation 70 errors. If you'd like to comment your template, you can prefix a *root level* 71 key with an underscore. Example: 72 73 ``` json 74 { 75 "_comment": "This is a comment", 76 "builders": [ 77 {} 78 ] 79 } 80 ``` 81 82 **Important:** Only *root level* keys can be underscore prefixed. Keys within 83 builders, provisioners, etc. will still result in validation errors. 84 85 ## Example Template 86 87 Below is an example of a basic template that could be invoked with `packer build`. It would create an instance in AWS, and once running copy a script to it and run that script using SSH. 88 89 -> **Note:** This example requires an account with Amazon Web Services. There are a number of parameters which need to be provided for a functional build to take place. See the [Amazon builder](/docs/builders/amazon.html) documentation for more information. 90 91 ``` json 92 { 93 "builders": [ 94 { 95 "type": "amazon-ebs", 96 "access_key": "...", 97 "secret_key": "...", 98 "region": "us-east-1", 99 "source_ami": "ami-fce3c696", 100 "instance_type": "t2.micro", 101 "ssh_username": "ubuntu", 102 "ami_name": "packer {{timestamp}}" 103 } 104 ], 105 106 "provisioners": [ 107 { 108 "type": "shell", 109 "script": "setup_things.sh" 110 } 111 ] 112 } 113 ```