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

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…

24 IBM offerings winning TrustRadius 2024 Top Rated Awards

2 min read - TrustRadius is a buyer intelligence platform for business technology. Comprehensive product information, in-depth customer insights and peer conversations enable buyers to make confident decisions. “Earning a Top Rated Award means the vendor has excellent customer satisfaction and proven credibility. It’s based entirely on reviews and customer sentiment,” said Becky Susko, TrustRadius, Marketing Program Manager of Awards. Top Rated Awards have to be earned: Gain 10+ new reviews in the past 12 months Earn a trScore of 7.5 or higher from…

IBM Tech Now: April 8, 2024

< 1 min read - ​Welcome IBM Tech Now, our video web series featuring the latest and greatest news and announcements in the world of technology. Make sure you subscribe to our YouTube channel to be notified every time a new IBM Tech Now video is published. IBM Tech Now: Episode 96 On this episode, we're covering the following topics: IBM Cloud Logs A collaboration with IBM watsonx.ai and Anaconda IBM offerings in the G2 Spring Reports Stay plugged in You can check out the…

IBM Newsletters

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