August 30, 2022 By Juan Pinzon 3 min read

What is the IBM Packer Plugin, and how can you create a custom image on IBM Cloud – VPC Infrastructure?

Packer is HashiCorp’s open-source tool for creating custom machine images from a single source configuration. This means users can customize an image with a pre-configured operating system and installed software for a specific use-case and then use it to quickly launch completely provisioned and configured instances.

What is the IBM Packer Plugin?

On the other hand, a Packer Plugin allows new functionality to be added to Packer without modifying the Packer core. The IBM Packer Plugin is a separate, standalone application; the core of Packer starts and communicates with it, and the plugin enables Packer to connect to and work with IBM Cloud resources. 

IBM Packer Plugin adds on two Builders — one for Classic and one for VPC. A Builder is a Packer component responsible for creating a machine image. First, the Builder reads in a Packer Template — a configuration file that defines the image you want to build and how to build it. From this configuration file, the Builder takes a source OS (Linux- or Windows-based) and provisions a Virtual Server Instance (VSI) on IBM Cloud. Then, the Builder installs software for a specific use-case and generates an image out of the VSI. This generated image can be reused to launch new completely provisioned and configured VSIs instances within IBM Cloud. 

Therefore, by using the IBM Packer Plugin, you can quickly create identical machine images from a single source configuration on both Classic and VPC infrastructure.

Builders

  • Classic: The classic builder supports the creation of custom images (.VHD) on IBM Cloud – Classic Infrastructure.
  • VPC: The vpc builder supports the creation of custom images on IBM Cloud – VPC Infrastructure.

IBM Packer Plugin workflow

Prerequisites 

Prepare your end to run the plugin:

  • Install Packer >= 1.7
  • Install Ansible >= 2.10, if Ansible is your preferred Provisioner (recommended)
  • Install Go >= 1.17, if you want to use manual installation
    • Environment variables for golang setup:
      export GOPATH=$HOME/go
      export GOROOT=/usr/local/go
      export PATH=$PATH:$GOPATH/bin:$GOROOT/bin
      export PACKERPATH=/usr/local/packer
      export PATH=$PATH:$PACKERPATH
    • For Windows image, install the Python package for winrm:
       pip3 install --ignore-installed "pywinrm>=0.2.2" --user

Usage

Create configuration files and folders

From the IBM Packer Plugin repo:

  • Create your preferred folder (i.e., mkdir $HOME/packer-plugin-ibmcloud/).
  • Create the .env file and set IBM Cloud Credentials. Also, set Packer and Ansible environment variables:
    # VPC
    export IBM_API_KEY=""
    # Classic
    export SL_USERNAME=""
    export SL_API_KEY=""
    
    export ANSIBLE_INVENTORY_FILE="provisioner/hosts"
    export ANSIBLE_HOST_KEY_CHECKING=False
    export PACKER_LOG=1
    export PACKER_LOG_PATH="packerlog/packerlog.txt"
    export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
  • Copy the Packer Templates examples folder: cp -r examples $HOME/packer-plugin-ibmcloud/. This folder will store Packer Template examples for different OS and Provisioners.
  • Copy the Windows-based VSI config scripts folder: cp -r scripts $HOME/packer-plugin-ibmcloud/. This folder will store required config scripts to setup WinRM communication with Windows VSIs.
  • Copy the Ansible playbooks folder: cp -r provisioner $HOME/packer-plugin-ibmcloud/. This folder will store Provisioner’s scripts.
  • Create the Packer log folder (recall env variable PACKER_LOG_PATH) cp -r packerlog $HOME/packer-plugin-ibmcloud/.

Use the packer init command

Starting with version 1.7, Packer supports third-party plugin installation using the packer init command (read the Packer documentation for more information). packer init downloads the Packer Plugin binaries required in your Packer Template. To install a Packer Plugin, just copy and paste the required_plugins block inside your Packer Template:

packer {
    required_plugins {
        ibmcloud = {
            version = ">=v3.0.0"
            source = "github.com/IBM/ibmcloud"
        }
    }
}

Then, run packer init -upgrade <packer-template-name>.

Note: Be aware that packer init does not work with legacy JSON templates. Upgrade your JSON config files to HCL. The IBM Packer plugin will be installed on $HOME/.packer.d/plugins.

Run the Packer Plugin

  • Run the source command to read and execute commands from the .env file: source .env.
  • Finally, run the Packer plugin commands:
    • packer validate examples/build.vpc.centos.pkr.hcl
    • packer build examples/build.vpc.centos.pkr.hcl

Conclusion

Packer Plugins allow new functionality to be added to Packer without modifying the Packer core. The IBM Packer Plugin is a completely separate, standalone application that can be used to create custom images on IBM Cloud – VPC Infrastructure and then use those images to quickly launch completely provisioned and configured instances. Moreover, the automation to use this tool will help you reduce the amount of time spent on manual processes and configuration and let you use IBM Packer Plugin right away.

If you have feedback, suggestions or questions about this post, please reach out to me here

Was this article helpful?
YesNo

More from Cloud

Enhance your data security posture with a no-code approach to application-level encryption

4 min read - Data is the lifeblood of every organization. As your organization’s data footprint expands across the clouds and between your own business lines to drive value, it is essential to secure data at all stages of the cloud adoption and throughout the data lifecycle. While there are different mechanisms available to encrypt data throughout its lifecycle (in transit, at rest and in use), application-level encryption (ALE) provides an additional layer of protection by encrypting data at its source. ALE can enhance…

Attention new clients: exciting financial incentives for VMware Cloud Foundation on IBM Cloud

4 min read - New client specials: Get up to 50% off when you commit to a 1- or 3-year term contract on new VCF-as-a-Service offerings, plus an additional value of up to USD 200K in credits through 30 June 2025 when you migrate your VMware workloads to IBM Cloud®.1 Low starting prices: On-demand VCF-as-a-Service deployments begin under USD 200 per month.2 The IBM Cloud benefit: See the potential for a 201%3 return on investment (ROI) over 3 years with reduced downtime, cost and…

The history of the central processing unit (CPU)

10 min read - The central processing unit (CPU) is the computer’s brain. It handles the assignment and processing of tasks, in addition to functions that make a computer run. There’s no way to overstate the importance of the CPU to computing. Virtually all computer systems contain, at the least, some type of basic CPU. Regardless of whether they’re used in personal computers (PCs), laptops, tablets, smartphones or even in supercomputers whose output is so strong it must be measured in floating-point operations per…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters