Customize an Azure Linux VM with Cloud-init

45 minutes
  • 2 Learning Objectives

About this Hands-on Lab

This hands-on lab will demonstrate how to create an automated startup configuration file to pass into VMs using cloud-init.

**Cloud-init** is an open-source tool for Linux cloud VMs, which has native support in Azure. It is important to note that cloud-init configuration is NOT in the form of a shell script, but uses modules in YAML syntax, which can be a learning curve for those used to shell scripting. The lab’s primary focus will concentrate on formatting our configuration file.

Mastering cloud-init enables automation in VM configuration, which is essential for auto-scaling services such as VM Scale Sets.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create First VM via Command Line and Pass in cloud-init Configuration File
  1. Create and pass in the configuration file as custom data.
  2. Create the VM.
  3. Open port 80.
  4. Change the resource group field to your unique lab resource group.
Create Second VM via Web Portal and Pass in cloud-init Configuration File
  1. Be sure to use an Ubuntu distribution.
  2. Copy/paste the contents of the configuration file in the Custom Data field.

Additional Resources

As the IT administrator for Ctrl-Alt-Sweets, makers of the world's finest chocolate cakes, you have been tasked with creating a web server for the company's website. As a proof-of-concept for future scaling architectures, you need to automate the post-boot configuration process of taking a generic Linux VM and configuring it to host your website.

The configuration steps you will automate include:

  • Updating VM packages and repositories
  • Installing necessary software (NGINX, Git)
  • Downloading custom website from a managed GitHub repo
  • Deleting the default NGINX website data
  • Moving downloaded web data to the NGINX directory
  • Restarting the NGINX service

All of the magic of this lab relies on a configuration file that we will pass onto our VM as custom data when first creating it. The contents of the configuration file we will be using are below, which can be copy/pasted to help complete the lab. Be aware that the file is in YAML formatting, so tabs and spacing do matter:

package_update: true
package_upgrade: true
  - nginx
  - git
  - git clone
  - rm /var/www/html/*
  - mv cas-demo-website/* /var/www/html/
  - systemctl restart nginx

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?