Cloud InitIn the previous post we’ve seen how to setup and configure Cloud Automation Services, how to use Cloud Assembly to create a fully Cloud agnostic blueprint, how to use input variables and how to integrate Cloud Automation Services with Puppet. In this post I will discuss how to use Cloud-Init to customize the deployment eg. how to install applications on top of that virtual machine component in the blueprint.

In vRealize Automation this process depends on a vRealize Automation guest- and a bootstrap agent. With Cloud Automation Services, VMware stepped away from this and adopted an industry standard method called Cloud-Init.

 

What is Cloud-Init?

When deploying virtual machines using Cloud Automation Services, every instance starts out as a clone of a template, ami, or image. To give the virtual machine its specific role and configuration you need a tool that does this customization. Cloud-init is the service that is installed inside the instance and applies a cloud-config automatically as soon as the instance is started. Cloud-config is the language of the scripts that cloud-init knows to execute.

While cloud-init started life in Ubuntu, it is now available for most major Linux and FreeBSD operating systems. It is currently installed in the Ubuntu Cloud Images and also in the official Ubuntu images available on EC2, Azure, GCE and many other clouds. For a list of Cloud-Init enabled virtual machines in Azure see this list.

For Microsoft Windows workloads, the equivalent is CloudBase-init but is this is currently not usable within Cloud Assembly.

Cloud-Init starts early at boot, retrieves metadata that has been provided from an external provider (metadata) or by direct user data supplied by the user.

You can use Cloud Init to perform a variety of actions:

  • Create users.
  • Setting a default locale.
  • Modifying configuration files.
  • Setting a hostname.
  • Creating files or folders.
  • Setting up mount points.
  • Configuring network devices.
  • Install applications.
  • …..

 

How do I prepare for Cloud-Init?

If you’re using images that are not Cloud-Init enabled, like on your vSphere environment, you can set it up in the following way.

Red Hat/CentOS

For Red Hat / CentOS run the following commands:

Ubuntu/Debian

For Ubuntu 14.04 and 16.04, please use vanilla cloud-init. Use the stock Ubuntu images provided by Canonical, which come with cloud-init pre-installed.
If you’re using non-Canonical images, use the following command-line to install cloud-init on Debian-based systems.

 

How do I use Cloud-Init?

Now that you’ve enabled Cloud-Init on your templates or images, it’s time to look at some examples/possibilities. Cloud-Init starts at the virtual machine’s first boot and retrieves the metadata that has been provided from an external provider. In the case of Cloud Automation Services, the metadata or instructions that are needed to perform are provided in the blueprint YAML code. See the image below:


 

In the red square, below line 13 you can now insert your code. Make sure you have the right indentation.

Cloud-Init examples

For instance, create a directory using Cloud-init.

Restart a service.

Set hostname.

Run commands on first boot.

Create a new user with ssh-rsa key access and bash shell environment.

Create a new user with password access and bash shell environment.

Install application packages like ‘apache‘, ‘php‘, ‘mysql-client‘, etc.

Install and configure a Postgres Database.
(credits: Cody  De Arkland)

This is not the end of this series because there are a lot of topics still to be explained. Next up, how to define dependencies in your CAS blueprints. So check-in regular for new content!