cloud-init overview

cloud-init is a tool for automating the initial setup of virtual machines, such as configuring the hostname, network interfaces, and authorized keys. It can be used to avoid conflicts on the network when provisioning virtual machines that have been deployed based on a template.

To use this tool, the cloud-init package must first be installed on the virtual machine. Once installed, the cloud-init service starts during the boot process to search for instructions on what to configure.

Use the options in the Run Once window to provide instructions for the immediate boot process. If you want these options to be persistent, set them in the New Virtual Machine, Edit Virtual Machine, and Edit Template windows.

cloud-init can be used to automate the configuration of virtual machines in a variety of scenarios. Some uses include:

Customize virtual machines using a standard template: You can use the Use Cloud-Init/Sysprep options in the Initial Run tab of the New Template and Edit Template windows to specify options for customizing virtual machines created based on that template.

Customize virtual machines using “Initial Run”: Administrators can use the cloud-init options in the Initial Run section of the Run Once window to initialize a virtual machine. This could be used to override settings set by a template.

Installing cloud-init

Preparation of the virtual machine with cloud-init is straightforward. The cloud-init package simply needs to be installed on the virtual machine that will be used as the baseline for the new template.

Here is a procedure that describes how to install cloud-init on your Red Hat Enterprise Linux 7 virtual machine:

  1. Using the Administration Portal, navigate to Virtual Machines tab.
  2. Select the appropriate virtual machine on the list and start it.
  3. When available, open the console and log in to the virtual machine as user root.
  4. Register and entitle the system with Red Hat Subscription Manager and enable the rhel-7- server-rpms and rhel-7-server-rh-common-rpms repositories with subscriptionmanager.
  5. Install the cloud-init package and dependencies using yum.

Preparing the template

As soon as the cloud-init package is installed on your Linux virtual machine, you can use that machine to create a template with cloud-init enabled.

Configure the template so that the advanced option Initial Run has the setting Use Cloud-Init/Sysprep selected. This enables additional configuration options for setting hostname, time zone, authentication and network properties, and running customer cloud-init scripts.

There are two easy ways to apply Initial Run settings to the template.

1. The template inherits any settings from the original virtual machine’s Initial Run configuration, just like it inherits other characteristics of the virtual machine. However, this means you have to change the base virtual machine’s settings and then create the template.
2. You can create the template normally, then use Edit Template to change the template’s Initial Run settings for cloud-init. The original virtual machine won’t have these settings applied, but machines created from the template will.

If the cloud-init settings are in the template, then when you create a new virtual machine, those Initial Run settings are applied to the virtual machine by default. You also have the option of overriding those settings from the New Virtual Machine window when you create the VM from the template.

Here is one way to prepare a cloud-init enabled template:

1. Using the Administration Portal, navigate to the Virtual Machines tab.

2. Right-click the virtual machine with the cloud-init package installed and select Make Template. Create a new sealed template based on the virtual machine.

3. Navigate to the Templates tab. Once the new template is ready, right-click on it and select Edit.

4. In the Edit Template window, ensure that the Show Advanced Options button was clicked and that you can access the advanced options. Click the Initial Run tab.

5. Mark the check box in the Use Cloud-Init/Sysprep line.

6. Clear the VM Hostname text field so that it is empty. Adjust the other options as desired.

– Authentication allows you to configure a user with a password and public keys authorized to allow SSH logins. This could create a new user or reconfigure an existing one in the virtual machine.
– Networks allow you to make some networking changes.
– Custom Script allows you to run a custom cloud-init script in cloud-config YAML format. See http://cloudinit.readthedocs.io for examples.

The edit template window

7. Click the OK button to accept the changes.

Now that you have a sealed template created with cloud-init enabled, you can create new virtual machines and reconfigure them using cloud-init.

Using cloud-init to configure a new virtual machine

You can deploy new virtual machines using the cloud-init enabled template you just created. This allows cloud-init to be used to customize a new virtual machine.

You could just create and run a new virtual machine from the template, and the cloud-init directives would be used to customize the resulting virtual machine. But you can also override the template’s cloud-init settings to further customize the resulting virtual machine. You can use cloud-init to configure the virtual machine’s name, create additional users, change network configuration, and specify a custom cloud-init script to run on boot.

Here is a procedure that describes how to start a virtual machine with a set of cloud-init settings:

1. Using the Administration Portal, navigate to the Virtual Machines tab.

2. Using a cloud-init enabled template, create a new virtual machine.

3. Once that machine becomes ready to use, highlight the virtual machine by clicking on its name in the available virtual machines list.

4. With the virtual machine highlighted, click the Run Once button to display the Run Virtual Machine(s) dialog.

5. Click the + icon next to Initial Run.

6. Make sure that the check box in the Use Cloud-Init line is marked.

7. Edit any of the Initial Run settings you want to override from the settings made by the template. For example, you might.

  • Specify the name of the virtual machine in the VM Hostname text field. If this is blank in the template, it should use the virtual machine name by default.
  • Click Authentication to reveal the Authentication section. Change the name or authentication information for a user to be created.
  • Adjust Networks settings.
  • Modify the Custom Script with a different cloud-init script in cloud-config YAML format.

NOTE: YAML used by cloud-init is sensitive to white-space indentation.

8. Click OK to initiate the creation of the virtual machine, with your customization, using cloud-init as the provisioning method.