github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/website/source/intro/getting-started/vagrant.html.md (about)

     1  ---
     2  description: |
     3      Packer also has the ability to take the results of a builder (such as an AMI or
     4      plain VMware image) and turn it into a Vagrant box.
     5  layout: intro
     6  next_title: Remote Builds and Storage
     7  next_url: '/intro/getting-started/remote-builds.html'
     8  page_title: Vagrant Boxes
     9  prev_url: '/intro/getting-started/parallel-builds.html'
    10  ...
    11  
    12  # Vagrant Boxes
    13  
    14  Packer also has the ability to take the results of a builder (such as an AMI or
    15  plain VMware image) and turn it into a [Vagrant](https://www.vagrantup.com) box.
    16  
    17  This is done using [post-processors](/docs/templates/post-processors.html).
    18  These take an artifact created by a previous builder or post-processor and
    19  transforms it into a new one. In the case of the Vagrant post-processor, it
    20  takes an artifact from a builder and transforms it into a Vagrant box file.
    21  
    22  Post-processors are a generally very useful concept. While the example on this
    23  getting-started page will be creating Vagrant images, post-processors have many
    24  interesting use cases. For example, you can write a post-processor to compress
    25  artifacts, upload them, test them, etc.
    26  
    27  Let's modify our template to use the Vagrant post-processor to turn our AWS AMI
    28  into a Vagrant box usable with the [vagrant-aws
    29  plugin](https://github.com/mitchellh/vagrant-aws). If you followed along in the
    30  previous page and setup DigitalOcean, Packer can't currently make Vagrant boxes
    31  for DigitalOcean, but will be able to soon.
    32  
    33  ## Enabling the Post-Processor
    34  
    35  Post-processors are added in the `post-processors` section of a template, which
    36  we haven't created yet. Modify your `example.json` template and add the section.
    37  Your template should look like the following:
    38  
    39  ``` {.javascript}
    40  {
    41    "builders": ["..."],
    42    "provisioners": ["..."],
    43    "post-processors": ["vagrant"]
    44  }
    45  ```
    46  
    47  In this case, we're enabling a single post-processor named "vagrant". This
    48  post-processor is built-in to Packer and will create Vagrant boxes. You can
    49  always create [new post-processors](/docs/extend/post-processor.html), however.
    50  The details on configuring post-processors is covered in the
    51  [post-processors](/docs/templates/post-processors.html) documentation.
    52  
    53  Validate the configuration using `packer validate`.
    54  
    55  ## Using the Post-Processor
    56  
    57  Just run a normal `packer build` and it will now use the post-processor. Since
    58  Packer can't currently make a Vagrant box for DigitalOcean anyways, I recommend
    59  passing the `-only=amazon-ebs` flag to `packer build` so it only builds the AMI.
    60  The command should look like the following:
    61  
    62  ``` {.text}
    63  $ packer build -only=amazon-ebs example.json
    64  ```
    65  
    66  As you watch the output, you'll notice at the end in the artifact listing that a
    67  Vagrant box was made (by default at `packer_aws.box` in the current directory).
    68  Success!
    69  
    70  But where did the AMI go? When using post-processors, Vagrant removes
    71  intermediary artifacts since they're usually not wanted. Only the final artifact
    72  is preserved. This behavior can be changed, of course. Changing this behavior is
    73  covered [in the documentation](/docs/templates/post-processors.html).
    74  
    75  Typically when removing intermediary artifacts, the actual underlying files or
    76  resources of the artifact are also removed. For example, when building a VMware
    77  image, if you turn it into a Vagrant box, the files of the VMware image will be
    78  deleted since they were compressed into the Vagrant box. With creating AWS
    79  images, however, the AMI is kept around, since Vagrant needs it to function.