Preparing Linux templates

As all Linux guests have OpenSSH Server preinstalled by default, you only need to ensure that a Linux template has cloud-init installed.

Cloud-init is required to configure user credentials and SSH access for virtual machines created from cloud images.

The easiest way to get a Linux template with cloud-init installed is to obtain it from its official repository or build one with the diskimage-builder tool. You can also create a Linux template from an existing boot volume.

Limitations

  • Disk images created with cloud-init typically contain only the root user without a predefined password or SSH keys. You can use user data and cloud-init to perform initial configuration tasks on VMs that will be deployed from the disk image, for example, create custom user accounts. For more options to customize a VM during boot, refer to the cloud-init documentation.

To build a Linux template

  1. Install the diskimage-builder package:

    # yum install diskimage-builder
    
  2. For the RHEL 7 guest OS, download the cloud image from the Red Hat Customer Portal (login required) and execute:

    # export DIB_LOCAL_IMAGE=<path_to_rhel7_image>
    
  3. Execute the disk-image-create command to build a disk image with installed cloud-init for the desired Linux guest. For example:

    # disk-image-create vm centos7 -t qcow2 -o centos7
    

    Where:

    • centos7 is the name of a guest OS. Can be one of the following: centos6, centos7, debian, rhel7, or ubuntu.

      By default, using the ubuntu element will create a disk image for Ubuntu 16.04. To build the Ubuntu 18.04 disk image, run:

      DIB_RELEASE=bionic disk-image-create vm ubuntu -t qcow2 -o ubuntu18
    • -o sets the name for the resulting disk image file.

  4. Upload the created disk image by using the vinfra tool to the compute cluster:

    # vinfra service compute image create centos7-image --os-distro centos7 \
    --disk-format qcow2 --file centos7.qcow2
    

    Where:

    • centos7-image is the name of a new image.
    • centos7 is the OS distribution. Can be one of the following: centos6, centos7, debian9, rhel7, ubuntu16.04, and ubuntu18.04.
    • centos7.qcow2 is the QCOW2-image created on step 3.

After the template is uploaded, you can use it to deploy virtual machines.

Using cloud-init with Linux cloud images

When deploying virtual machines from Linux cloud images (for example, Debian or Ubuntu), cloud-init applies the initial system configuration.

Cloud images do not contain predefined credentials. User accounts, passwords, and SSH settings are defined through cloud-init.

Access to such virtual machines is typically provided in one of the following ways:

  • by injecting an SSH key
  • by specifying user credentials in a cloud-init configuration

SSH keys selected at deployment are automatically injected into the guest operating system via cloud-init.

If neither a cloud-init configuration nor an SSH key is provided, you may not be able to log in to the virtual machine.

The following example creates a user account, sets a password, and enables SSH password authentication:

#cloud-config
users:
  - name: clouduser
    groups: sudo
    shell: /bin/bash
    sudo: ALL=(ALL) NOPASSWD:ALL
    lock_passwd: false

ssh_pwauth: true

chpasswd:
  expire: false
  list: |
    clouduser:<password>

runcmd:
  - systemctl restart ssh

Replace <password> with a secure password.

Cloud-init configuration is provided when creating the virtual machine. For details, refer to Creating virtual machines.