Deploying virtual machines (VMs) manually can be time-consuming, especially when repetitive configurations are involved. A more efficient approach involves creating a Cloud-Init ready Ubuntu VM template that can streamline deployments and automate configurations. In this guide, we'll walk you through the process of preparing a Cloud-Init ready template that integrates seamlessly with VMware Aria Automation.
Why Create a Cloud-Init Ready Template?
Cloud-Init is a powerful tool that enables you to automatically manage the configuration of a VM during its initialization phase. This includes installing necessary packages, updating configurations, and even running custom scripts. By creating a Cloud-Init ready Ubuntu VM template, you can automate repetitive tasks and reduce deployment time significantly.
Preparing the Cloud-Init Ready Cloneable Ubuntu Template
To get started, you'll need a clean Ubuntu installation. Ensure that your VM is up-to-date and has essential utilities like Git and SSH installed. The next steps are as follows:
-
Install Cloud-Init:
Confirm that Cloud-Init is installed on your VM with the command:
sudo apt-get install cloud-init -y
-
Remove Existing Cloud-Init Configurations:
If your Ubuntu installer used a live ISO, it likely has existing Cloud-Init configurations. Clean these up using:
sudo cloud-init clean
Additionally, delete two specific configuration files as they might interfere with new configurations:
sudo rm -rf /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg sudo rm -rf /etc/cloud/cloud.cfg.d/99-installer.cfg
-
Shut Down the VM:
Once you've cleaned the VM, shut it down to proceed with template creation:
sudo shutdown -h now
-
Set CD-ROM Drive to Passthrough:
Go to the VM’s hardware settings and adjust the CD-ROM drive to 'Passthrough CD-ROM'. This will enable future Cloud-Init configurations.
-
Convert the VM to a Template:
Once the VM is fully configured and cleaned, convert it to a template in your VMware environment. This template is now ready to be used with Aria Automation cloud templates.
Adding Cloud-Init Configuration to Cloud Assembly Templates
In Cloud Assembly, you can add initialization commands using the cloudConfig
section. The syntax is different for Linux and Windows operating systems. The example below demonstrates how to set up a simple Apache server and a MySQL database in Linux:
cloudConfig: |
#cloud-config
repo_update: true
repo_upgrade: all
packages:
- apache2
- php
- php-mysql
- libapache2-mod-php
- php-mcrypt
- mysql-client
runcmd:
- mkdir -p /var/www/html/mywordpresssite && cd /var/www/html && wget https://wordpress.org/latest.tar.gz && tar -xzf /var/www/html/latest.tar.gz -C /var/www/html/mywordpresssite --strip-components 1
- mysql -u root -pmysqlpassword -h ${DBTier.networks[0].address} -e "create database wordpress_blog;"
- mv /var/www/html/mywordpresssite/wp-config-sample.php /var/www/html/mywordpresssite/wp-config.php
- service apache2 reload
Troubleshooting Cloud-Init
If the Cloud-Init configuration is not working as expected, check the log output:
cat /var/log/cloud-init-output.log
Reviewing this log will provide insights into any errors or skipped commands during the initialization process.
Encrypting Access Credentials
To handle sensitive information securely, consider encrypting access credentials within your Cloud Assembly templates. For instance:
resources:
apitier:
type: Cloud.Machine
properties:
cloudConfig: |
#cloud-config
runcmd:
- export apikey=${base64_encode(input.username:input.password)}
- curl -i -H 'Accept:application/json' -H 'Authorization:Basic :$apikey' http://example.com
By implementing Cloud-Init in your Ubuntu VM templates, you can automate deployments, enforce standard configurations, and minimize manual intervention. This approach is particularly beneficial when managing multiple environments using VMware Aria Automation.