github.com/aspring/packer@v0.8.1-0.20150629211158-9db281ac0f89/website/source/docs/templates/introduction.html.markdown (about)

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