Use the 1&1 Packer Plug-In to Build 1&1 Images

Table of Contents

Introduction

This builder plugin extends Packer to support building images for 1&1.

Packer is a tool for creating machine and container images for multiple platforms from a single source configuration.

Requirements

  • A 1&1 Cloud Server account.
  • A Mac OSX, Linux, or Windows desktop.
  • An updated version of Packer installed and running.
  • A basic knowledge of Packer is helpful. More information about Packer can be found on the official website.

The 1&1 builder plug-in is automatically included with the latest version of Packer. No separate installation is required, but you may need to update your version of Packer.

Example 1: Create an Image

Once you have set everything up, you are ready to start with an example. To create an image using the 1&1 Packer Builder, you need to have a JSON template similar to the following example:

{
   "builders":[
      {
         "type":"oneandone",
         "disk_size":"50",
         "image_name":"test5",
         "source_image_name":"ubuntu1604-64min",
         "ssh_username" :"root"
      }
   ],
  "provisioners": [
    {
      "inline": [
        "echo foo"
      ],
      "type": "shell"
    }
  ]

}

This example consists of two sections.

  1. builder which is responsible for creating machines and generating images for various platforms. In this case we will need to use "type" : "oneandone". To get more details checkout this. To see other 1&1 parameters check out [this section](## Available config parameters).

  2. provisioner is where we define what packer needs to install on the machine prior turning it into 1&1 Image. In this case it is a simple shell command echo foo. To see what else provisioners can do have a look here.

Example 2: Build an Image

To build a 1&1 Packer image run:

packer build template.json

oneandone output will be in this color.

==> oneandone: Creating Server...
==> oneandone: Waiting for SSH to become available...
==> oneandone: Connected to SSH!
==> oneandone: Provisioning with shell script: /var/folders/by/8dsj76cs15jgx_fvjltwhpg40000gn/T/packer-shell240623297
    oneandone: foo
==> oneandone: Creating Snapshot...
==> profitbricks: Creating 1&1 snapshot...
==> profitbricks: Removing Server
Build 'oneandone' finished.

==> Builds finished. The artifacts of successful builds are:
--> oneandone: A snapshot was created: '4BAACD374100BF5E32341F01C12C7A67', 'packer-1479732612_20161121'

Available config parameters

Required

  • source_image_name (string) - 1&1 Server Appliance name of type IMAGE.

  • token (string) - 1&1 REST API Token. This can be specified via environment variable ONEANDONE_TOKEN

Optional

  • data_center_name - Name of virtual data center. Possible values "ES", "US", "GB", "DE". Default value "US"

  • disk_size (string) - Amount of disk space for this image in GB. Defaults to "50"

  • image_password (string) - Password for the server images.

  • image_name (string) - Resulting image. If "image_name" is not provided Packer will generate it

  • retries (int) - Number of retries Packer will make status requests while waiting for the build to complete. Default value "600".

  • url (string) - Endpoint for the 1&1 REST API. Default URL "https://cloudpanel-api.1and1.com/v1"

Other

If you want to check if your config file is in the correct format run following command:

$packer validate config.json

./bin/packer validate ~/oneandone.json 
Template validation failed. Errors are shown below.

Errors validating build 'oneandone'. 1 error(s) occurred:

* unknown configuration key: "sorce_image_name"

You can also let packer fix your config file by running:

$packer fix old.json > new.json

Support

Please report any issues via GitHub's issue tracker.

Comments

Tags: Packer