Streamlining Your Ubuntu 22.x Virtual Machine Setup with Cloud-init and VMware Aria Automation

Creating a Template in vSphere for Cloud-Init Automation

As I embarked on my latest project, I realized that I needed to create a template in vSphere for cloud-init automation. However, I did not want to use vSphere customization specifications but rather rely solely on cloud-init. After researching various posts and attempting different methods, I documented the steps that worked for me. In this blog post, I will share my experience and the procedures I followed to create a template in vSphere for cloud-init automation.

Step 1: Install Cloud-Init

The first step is to install cloud-init. Although it should already be installed, let’s be safe and ensure that it’s set up properly. To install cloud-init, run the following command in your terminal:

`sudo apt update && sudo apt install cloud-init`

Step 2: Clean Up Existing Cloud-Init Configurations

Newer Ubuntu installers use cloud-init themselves, so we need to clean up any existing cloud-init configurations. To do this, run the following command:

`sudo cloud-init clean –all`

This command will remove any existing cloud-init configurations.

Step 3: Remove Unnecessary Files

As of Ubuntu versions 20.04.x live server, we need to remove two existing files to ensure that cloud-init configuration will execute later on. The two files are:

* `/etc/cloud/cloud.cfg.d/`

* `/etc/cloud/cloud-config.json`

To remove these files, run the following commands:

`sudo rm -rf /etc/cloud/cloud.cfg.d/`

`sudo rm -rf /etc/cloud/cloud-config.json`

Step 4: Shut Down the VM

Now that we have cleaned up any existing cloud-init configurations and removed unnecessary files, it’s time to shut down the VM. To do this, run the following command:

`sudo poweroff`

Step 5: Set CD-ROM Device Mode to Passthrough CD-ROM

Under the VM hardware settings, ensure that the CD-ROM drive device mode is set to Passthrough CD-ROM. To do this, follow these steps:

1. Open the vSphere client and select the virtual machine you want to use as a template.

2. Click on the “Edit” button to edit the virtual machine settings.

3. In the “Hardware” section, click on the “CD/DVD” tab.

4. Select “Passthrough CD-ROM” as the device mode.

5. Click “OK” to save the changes.

Step 6: Shut Down and Convert to Template

Now that all the necessary steps have been completed, it’s time to shut down the VM and convert it to a template. To do this, run the following command:

`sudo poweroff`

Once the VM has shut down, follow these steps to convert it to a template:

1. Open the vSphere client and select the virtual machine you want to use as a template.

2. Click on the “Edit” button to edit the virtual machine settings.

3. In the “Hardware” section, click on the “CD/DVD” tab.

4. Select “Template” as the device mode.

5. Click “OK” to save the changes.

Your template is now ready to be used with VMware Aria Automation cloud templates.

Conclusion

Creating a template in vSphere for cloud-init automation can be a bit challenging, but following these steps will ensure that your template is properly set up and ready to use with VMware Aria Automation cloud templates. Remember to install cloud-init, clean up any existing configurations, remove unnecessary files, shut down the VM, set the CD-ROM device mode to Passthrough CD-ROM, and convert the VM to a template. With these steps, you’ll be well on your way to automating your cloud infrastructure with cloud-init and vSphere.

Leave a Reply