Deploying a custom image in a cloud environment can present certain challenges

Building automation around infrastructure deployment is key to ensuring rapid delivery of services in the cloud. Deploying standard image templates is a straightforward process on the IBM Cloud, and this can be automated for efficiency and to avoid manual errors. But what about deploying a custom image?  

Deploying a custom image in a cloud environment can present various challenges—ensuring proper formatting of images, encountering cloud server image limitations and compatibility, and the time required to upload and configure images, just to mention a few.  

Automation technology can drastically speed up the deployment of custom images, ensure best practices, and remove any chance of manual errors.    

Example code for an automation solution 

In this blog post, I will provide example code for a solution to automate deployment of a custom OS on a No OS IBM Cloud Bare Metal Server using Terraform and Ansible technology. Terraform will be used to deploy the compute resources—in this case a virtual server that will serve as our Preboot Execution Environment (PXE) server and the No OS bare metal server. Then, Ansible will be used to set up the PXE server.

Specifically, the code in this example will do the following:

  • Create a new VLAN for PXE deployment environment
  • Create a new Subnet on the PXE Server VLAN for use with DHCP
  • Deploy an hourly virtual server as the PXE Server (Ubuntu 16 2×4 Instance)
  • Run Ansible Playbooks to:
    • Update the PXE Server Operating System
    • Install and configure Dnsmasq and PXE
    • Download an Ubuntu 18 Server ISO
    • Copy ISO netboot tools in to the tftpboot directory
    • Copy Ubuntu ISO files to PXE Directory
    • Update the dnsmasq server configuration
    • Configure DHCP settings
  • Create an IBM Cloud support ticket to have the virtual servers private IP set as the DHCP helper address on the appropriate VLAN
  • Deploy a No OS server on to the PXE server VLAN


In order to use this example code, you will need an upgraded IBM Cloud account. Don’t have an IBM Cloud account yet?  Sign up here.

  • Terraform and the IBM Terraform provider plugin installed. Guide.
  • Ansible installed. Guide.
  • An IBM Cloud PaaS and IaaS API key. Guide.

If you already have Terraform v0.12 installed, you will need to use a different machine or downgrade. The IBM Cloud Provider plugin only supports pre-v0.12 Terraform versions.

Step-by-step process to use the example code

1. Download the example code

$ git clone
$ cd ibm_pxe_terraform

2. Update the install.yml file with your local SSH key

If you don’t have an SSH key generated, you will need to create one. The SSH key will be used to authenticate with our PXE instance for Ansible communication. The example below will work on macOS and Linux. If you need different options, please see this guide on how to generate an SSH Key.

$ ssh-keygen -o -t rsa -b 4096

Replace your_public_ssh_key_here with your Public SSH Key in the install.yml file.

$ nano/vi install.yml

3. Configuring the provider

Copy the credentials template file and update it with your IBM Cloud details. See this page for more information about provider variables.

$ cp credentials.tfvars.tpl credentials.tfvars
$ nano/vi credentials.tfvars

4. Initialize Terraform

Run the terraform init command to initialize the directory containing your Terraform files.

$ terraform init

5. Create the initial Terraform plan

The plan command is used to create an execution plan based on your Terraform files.

$ terraform plan -var-file='./credentials.tfvars' -out project.tfplan

6. Deploy your infrastructure

With our plan created, we can now get to the task at hand of deploying infrastructure assets.

$ terraform apply project.tfplan

7. Run Ansible playbook

Run the Ansible playbook to configure your PXE server. 

$ ansible-playbook -i Hosts/inventory.env Playbooks/deploy-environment.yml

You may need to reboot the bare metal server via the Customer portal or API in order for it to pick up the new DHCP Helper IP address.

8. Log in to the NO OS Server IPMI and complete the install

Questions and issues

For any issues or questions, please visit the GitHub repositories issues page.


More from Cloud

IBM Tech Now: October 2, 2023

< 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 86 On this episode, we're covering the following topics: AI on IBM Z IBM Maximo Application Suite 8.11 IBM NS1 Connect Stay plugged in You can check out the IBM Blog Announcements for a…

IBM Cloud inactive identities: Ideas for automated processing

4 min read - Regular cleanup is part of all account administration and security best practices, not just for cloud environments. In our blog post on identifying inactive identities, we looked at the APIs offered by IBM Cloud Identity and Access Management (IAM) and how to utilize them to obtain details on IAM identities and API keys. Some readers provided feedback and asked on how to proceed and act on identified inactive identities. In response, we are going lay out possible steps to take.…

IBM Cloud VMware as a Service introduces multitenant as a new, cost-efficient consumption model

4 min read - Businesses often struggle with ongoing operational needs like monitoring, patching and maintenance of their VMware infrastructure or the added concerns over capacity management. At the same time, cost efficiency and control are very important. Not all workloads have identical needs and different business applications have variable requirements. For example, production applications and regulated workloads may require strong isolation, but development/testing, training environments, disaster recovery sites or other applications may have lower availability requirements or they can be ephemeral in nature,…

IBM accelerates enterprise AI for clients with new capabilities on IBM Z

5 min read - Today, we are excited to unveil a new suite of AI offerings for IBM Z that are designed to help clients improve business outcomes by speeding the implementation of enterprise AI on IBM Z across a wide variety of use cases and industries. We are bringing artificial intelligence (AI) to emerging use cases that our clients (like Swiss insurance provider La Mobilière) have begun exploring, such as enhancing the accuracy of insurance policy recommendations, increasing the accuracy and timeliness of…