github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/website/source/docs/templates/post-processors.html.markdown (about) 1 --- 2 layout: "docs" 3 page_title: "Templates: Post-Processors" 4 --- 5 6 # Templates: Post-Processors 7 8 The post-processor section within a template configures any post-processing 9 that will be done to images built by the builders. Examples of post-processing 10 would be compressing files, uploading artifacts, etc. 11 12 Post-processors are _optional_. If no post-processors are defined within a template, 13 then no post-processing will be done to the image. The resulting artifact of 14 a build is just the image outputted by the builder. 15 16 This documentation page will cover how to configure a post-processor in a 17 template. The specific configuration options available for each post-processor, 18 however, must be referenced from the documentation for that specific post-processor. 19 20 Within a template, a section of post-processor definitions looks like this: 21 22 <pre class="prettyprint"> 23 { 24 "post-processors": [ 25 ... one or more post-processor definitions here ... 26 ] 27 } 28 </pre> 29 30 For each post-processor definition, Packer will take the result of each of the 31 defined builders and send it through the post-processors. This means that if you 32 have one post-processor defined and two builders defined in a template, the 33 post-processor will run twice (once for each builder), by default. There are 34 ways, which will be covered later, to control what builders post-processors 35 apply to, if you wish. 36 37 ## Post-Processor Definition 38 39 Within the `post-processors` array in a template, there are three ways to 40 define a post-processor. There are _simple_ definitions, _detailed_ definitions, 41 and _sequence_ definitions. Don't worry, they're all very easy to understand, 42 and the "simple" and "detailed" definitions are simply shortcuts for the 43 "sequence" definition. 44 45 A **simple definition** is just a string; the name of the post-processor. An 46 example is shown below. Simple definitions are used when no additional configuration 47 is needed for the post-processor. 48 49 <pre class="prettyprint"> 50 { 51 "post-processors": ["compress"] 52 } 53 </pre> 54 55 A **detailed definition** is a JSON object. It is very similar to a builder 56 or provisioner definition. It contains a `type` field to denote the type of 57 the post-processor, but may also contain additional configuration for the 58 post-processor. A detailed definition is used when additional configuration 59 is needed beyond simply the type for the post-processor. An example is shown below. 60 61 <pre class="prettyprint"> 62 { 63 "post-processors": [ 64 { 65 "type": "compress", 66 "format": "tar.gz" 67 } 68 ] 69 } 70 </pre> 71 72 A **sequence definition** is a JSON array comprised of other **simple** or 73 **detailed** definitions. The post-processors defined in the array are run 74 in order, with the artifact of each feeding into the next, and any intermediary 75 artifacts being discarded. A sequence definition may not contain another 76 sequence definition. Sequence definitions are used to chain together multiple 77 post-processors. An example is shown below, where the artifact of a build is 78 compressed then uploaded, but the compressed result is not kept. 79 80 <pre class="prettyprint"> 81 { 82 "post-processors": [ 83 [ 84 "compress", 85 { "type": "upload", "endpoint": "http://example.com" } 86 ] 87 ] 88 } 89 </pre> 90 91 As you may be able to imagine, the **simple** and **detailed** definitions 92 are simply shortcuts for a **sequence** definition of only one element. 93 94 ## Input Artifacts 95 96 When using post-processors, the input artifact (coming from a builder or 97 another post-processor) is discarded by default after the post-processor runs. 98 This is because generally, you don't want the intermediary artifacts on the 99 way to the final artifact created. 100 101 In some cases, however, you may want to keep the intermediary artifacts. 102 You can tell Packer to keep these artifacts by setting the 103 `keep_input_artifact` configuration to `true`. An example is shown below: 104 105 <pre class="prettyprint"> 106 { 107 "post-processors": [ 108 { 109 "type": "compress", 110 "keep_input_artifact": true 111 } 112 ] 113 } 114 </pre> 115 116 This setting will only keep the input artifact to _that specific_ 117 post-processor. If you're specifying a sequence of post-processors, then 118 all intermediaries are discarded by default except for the input artifacts 119 to post-processors that explicitly state to keep the input artifact. 120 121 <div class="alert alert-info alert-block"> 122 <strong>Note:</strong> The intuitive reader may be wondering what happens 123 if multiple post-processors are specified (not in a sequence). Does Packer require the 124 configuration to keep the input artifact on all the post-processors? 125 The answer is no, of course not. Packer is smart enough to figure out 126 that at least one post-processor requested that the input be kept, so it will keep 127 it around. 128 </div> 129 130 ## Run on Specific Builds 131 132 You can use the `only` or `except` configurations to run a post-processor 133 only with specific builds. These two configurations do what you expect: 134 `only` will only run the post-processor on the specified builds and 135 `except` will run the post-processor on anything other than the specified 136 builds. 137 138 An example of `only` being used is shown below, but the usage of `except` 139 is effectively the same. `only` and `except` can only be specified on "detailed" 140 configurations. If you have a sequence of post-processors to run, `only` 141 and `except` will only affect that single post-processor in the sequence. 142 143 <pre class="prettyprint"> 144 { 145 "type": "vagrant", 146 "only": ["virtualbox-iso"] 147 } 148 </pre> 149 150 The values within `only` or `except` are _build names_, not builder 151 types. If you recall, build names by default are just their builder type, 152 but if you specify a custom `name` parameter, then you should use that 153 as the value instead of the type.