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

Prerequisites

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?
YesNo

More from Cloud

Bigger isn’t always better: How hybrid AI pattern enables smaller language models

5 min read - As large language models (LLMs) have entered the common vernacular, people have discovered how to use apps that access them. Modern AI tools can generate, create, summarize, translate, classify and even converse. Tools in the generative AI domain allow us to generate responses to prompts after learning from existing artifacts. One area that has not seen much innovation is at the far edge and on constrained devices. We see some versions of AI apps running locally on mobile devices with…

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…

The advantages and disadvantages of private cloud 

6 min read - The popularity of private cloud is growing, primarily driven by the need for greater data security. Across industries like education, retail and government, organizations are choosing private cloud settings to conduct business use cases involving workloads with sensitive information and to comply with data privacy and compliance needs. In a report from Technavio (link resides outside ibm.com), the private cloud services market size is estimated to grow at a CAGR of 26.71% between 2023 and 2028, and it is forecast to increase by…

IBM Newsletters

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