Bookmark this page

Guided Exercise: Automating Virtual Machine Configuration

In this exercise, you will deploy a virtual machine using a template configured to use cloud-init.

Outcomes

You should be able to prepare a template that is installed with cloud-init, and create a virtual machine with a customized configuration using cloud-init to apply your customization.

Log in to workstation as student using student as the password.

On workstation, run the lab vms-cloud-init start command. This command runs a start script that determines if the Red Hat Virtualization environment is configured and working.

[student@workstation ~]$ lab vms-cloud-init start
  1. On workstation, open Firefox and using the https://rhvm.lab.example.com URL go to the RHV-M web interface. Click on the Administration Portal link and log in to the web interface as the admin user, with the internal profile, using redhat as the password.

  2. Install cloud-init on rhel-vm2.

    1. Navigate to Virtual Machines by clicking on Compute in the menu bar, and then selecting Virtual Machines.

    2. Highlight the row containing the rhel-vm2 virtual machine by clicking an empty cell in that row. Ensure that the rhel-vm2 virtual machine is running. If it is not, click the Run button to start it.

    3. When available, open the console and log in to rhel-vm2 as user root with redhat as the password.

    4. To install the cloud-init software package on your rhel-vm2 virtual machine, you normally would ensure the system is registered with Red Hat Subscription Manager and has the correct entitlements and Yum repositories enabled.

      In this classroom environment, this step has been modified because the classroom might not have access to the Content Distribution Network or a Red Hat Satellite server. Instead, local Yum repositories have been provided, which contain the correct packages.

      In a previous lab, you downloaded a file to enable the local Yum repositories. Verify that the rhel_dvd repository is accessible using the yum repolist command.

      [root@rhel-vm2 ~]# yum repolist
      ...output omitted...
      repo id         repo name                           status
      rhel_dvd        Remove classroom copy of dvd        5,152
      ...output omitted...

      If you do not see the rhel_dvd repository, download the rhel_dvd.repo file from http://materials.example.com/yum.repos.d/rhel_dvd.repo and place it in the /etc/yum.repos.d/ directory.

      [root@rhel-vm2 ~]# curl http://materials.example.com/yum.repos.d/rhel_dvd.repo \
      -o /etc/yum.repos.d/rhel_dvd.repo
      ...output omitted...

      Install the cloud-init package with all dependencies using the yum command.

      [root@rhel-vm2 ~]# yum -y install cloud-init
      ...output omitted...
    5. Shut down the rhel-vm2 virtual machine using the systemctl poweroff command.

      [root@rhel-vm2 ~]# systemctl poweroff
  3. Create a new template named rhel-cloud-template from the rhel-vm2 virtual machine.

    1. With the rhel-vm2 virtual machine row highlighted, click the three vertical dots to the right of the Create Snapshot button, and then select Make Template.

    2. Use the New Template window to specify all the settings needed to create the template.

    3. In the Name text field, type the name rhel-cloud-template for the template.

    4. In the Description text field, type the description cloud-init based template for the template.

    5. In the Alias text field, type the name rhel7-cloud-init for the alias.

    6. If it is not already selected, select the Seal Template check box.

    7. Leave the other options as their default settings. Click the OK button to create the template.

    8. Notice that the rhel-vm2 virtual machine and all of its disks are locked. This step can take a couple of minutes to finish. When the process of creating the template is complete, the virtual machine is released from its locked state.

  4. Configure rhel-cloud-template to use cloud-init for its Initial Run. These settings will be inherited by any virtual machine created from this template.

    1. View existing templates by clicking Compute in the menu bar, and then selecting Templates.

    2. Ensure the row containing rhel-cloud-template is highlighted by clicking an empty cell in that row.

    3. Click the Edit button to edit the properties of rhel-cloud-template.

    4. In the Edit Template window, click the Show Advanced Options button, if it is visible, to access the advanced options. Click the Initial Run tab.

    5. Ensure that the check box for Use Cloud-Init/Sysprep is selected.

    6. Make sure the VM Hostname text field is empty.

    7. Leave the other options with their default values. Click the OK button to accept the changes.

  5. Create a new virtual machine named rhel-cloud-vm, based on the template rhel-cloud-template.

    1. On the Compute >> Virtual Machines page, click the New button. The New Virtual Machine window displays.

    2. In the Cluster menu, choose clusterone.

    3. In the Template menu, choose rhel-cloud-template.

    4. In the Name field, type the name rhel-cloud-vm for the virtual machine.

    5. In the Description field, type the description RHEL Guest for cloud-init test for the virtual machine.

    6. Notice that the network configuration matches the one from the original rhel-vm2 virtual machine, and that you are unable to create any new disk images.

    7. Leave all the other options as they are and click the OK button to create the new template-based virtual machine.

    8. Wait until the virtual machine is created.

  6. Customize the cloud-init configuration for the new rhel-cloud-vm virtual machine, and then run it for the first time.

    1. A new virtual machine created from a template has an initial state of stopped. Ensure the row containing the rhel-cloud-vm virtual machine is highlighted by clicking an empty cell in that row.

    2. With the row containing rhel-cloud-vm highlighted, click the Run drop-down menu and select Run Once to display the Run Virtual Machine(s) dialog.

    3. Click the + icon next to Initial Run.

    4. Make sure that the check box in the Use Cloud-Init line is selected.

    5. In the VM Hostname text field, ensure that the rhel-cloud-vm name is present. This will change the hostname of the new virtual machine.

    6. Click Authentication to reveal the Authentication section. Enter a User Name of developer, and a Password of redhat. Enter the password again in the Verify Password field.

    7. Click OK to initiate the creation of the virtual machine, using cloud-init as the provisioning method.

    8. Once the virtual machine is running, click the Console button and verify the changes made by cloud-init. Note that it may take a minute before the virtual machine starts booting from its hard drive. Log in as the developer user with redhat as the password. Notice that the hostname of the virtual machine is rhel-cloud-vm. When you have finished reviewing the changes to the rhel-cloud-vm virtual machine, close the virtual machine console.

  7. The exercise is complete, but you must clean up your classroom environment in order to preserve resources for upcoming exercises. Delete the rhel-cloud-vm virtual machine and the rhel-cloud-template template from your RHV environment.

    1. View available virtual machines by clicking on Compute in the menu bar, and then selecting Virtual Machines. From the list of available virtual machines, highlight the row for the rhel-cloud-vm virtual machine by clicking an empty cell in that row. Click the Shutdown drop-down menu and then select Power Off. When the Power Off Virtual Machine(s) window appears, confirm powering off the machine by clicking the OK button.

    2. With the row containing the rhel-cloud-vm virtual machine highlighted, click the Remove button to remove the virtual machine. When the Remove Virtual Machine(s) window displays, make sure the check box next to Remove Disk(s) is selected. Confirm the removal of the machine by clicking the OK button.

    3. Notice that the rhel-cloud-vm has been removed and is no longer present on the list of available virtual machines.

    4. View available templates by clicking on Compute in the menu bar, and then selecting Templates. From the list of available templates, highlight the row containing rhel-cloud-template by clicking an empty cell in that row.

    5. With the row containing the rhel-cloud-template template highlighted, click the Remove button to remove the template. When the Remove Template(s) window displays, click the OK button to confirm the removal of the template.

    6. Notice that the template, rhel-cloud-template, has been removed and is no longer present on the list of available templates. Log out from the Administration Portal.

Finish

On workstation, run the lab vms-cloud-init finish script to complete this exercise.

[student@workstation ~]$ lab vms-cloud-init finish

This concludes the guided exercise.

Revision: rh318-4.3-c05018e