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