July 31, 2019 By Ryan Tiffany 3 min read

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 https://github.com/greyhoundforty/ibm_pxe_terraform.git
$ 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.

Was this article helpful?

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