Skip to content
This repository has been archived by the owner. It is now read-only.
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.

Packer Common

When using Packer extensively, templates can be difficult to maintain; Packer common aims to fix it, by allowing to define separate Packer templates for builders, provisioners and project-specific items, merging them at execution time.

How to Run

Invoking Packer Common is simple:

curl -L --no-sessionid | bash -s -- ./ami.env

To run Packer Common you need:

  • A .env file (in this example ami.env) that defines all environment variables used by Packer logic; the .env file will include - amongst many other variables used by Packer Templates - a builder, a provisioner and a project-specific template "snippet":
  • The project-specific Packer logic, in this example packer-ami.rb

Template Composition

Based on the variables, the following "snippets" are fetched and merged:

  • The common builder
  • The common provisioner
  • The project-specific template "snippet", which can patch bits and pieces of builders and provisioners; an example is reported below

A project-specific Packer Common snippet

Racker::Processor.register_template do |t|
  t.provisioners = {
    10 => {
      "chef" => {
        "json"=> {
          "name"=> "img-basic"
        "run_list" => [ "img-basic::default" ]
    20 => {
      "yum-clean-all" => {
        "type"=> "shell",
        "inline" => [
          "sudo yum -y clean all",
          "sudo rm -f /var/log/*",
          "sudo rm -rf /tmp/*"
  }['amazon'] = {
    "ami_block_device_mappings" => [
        "device_name" => "/dev/sda1",
        "volume_size" => 12,
        "delete_on_termination" => true
        "device_name" => "/dev/sdb",
        "virtual_name" => "ephemeral0"
        "device_name" => "/dev/sdc",
        "virtual_name" => "ephemeral1"

Racker allows to generate Packer templates from a list of template "fragments" (or Racker templates).

Reusable Packer Template "snippets"

This is the list of currently available Packer Template "snippets" that can be reused with Packer Common:

Using Chef/Berkshelf

When Chef is involved, Packer Common will run some tasks before invoking racker and packer:

  1. Run Berkshelf to resolve all cookbooks needed
  2. Download and unpack databags
  3. Resolve Racker templates (from a Github repo) delivers these features, reading configurations from environment variables; check packer.env.sample for more info


Delivers image composition and building using Packer, Racker, Chef and Berkshelf



No packages published