7.8. Using Cloud-Init to Automate the Configuration of Virtual Machines
7.8.1. Cloud-Init Use Case Scenarios
- Virtual Machines Created Based on TemplatesYou can use the Cloud-Init options in the Initial Run section of the Run Once window to initialize a virtual machine that was created based on a template. This allows you to customize the virtual machine the first time that virtual machine is started.
- Virtual Machine TemplatesYou 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.
- Virtual Machine PoolsYou can use the Use Cloud-Init/Sysprep options in the Initial Run tab of the New Pool window to specify options for customizing virtual machines taken from that virtual machine pool. This allows you to specify a set of standard settings that will be applied every time a virtual machine is taken from that virtual machine pool. You can inherit or override the options specified for the template on which the virtual machine is based, or specify options for the virtual machine pool itself.
7.8.2. Installing Cloud-Init
Procedure 7.10. Installing Cloud-Init
- Log on to the virtual machine.
- Enable the required repositories:
- Red Hat Enterprise Linux 6:
# subscription-manager repos --enable=rhel-6-server-rpms # subscription-manager repos --enable=rhel-6-server-rh-common-rpms
- Red Hat Enterprise Linux 7:
# subscription-manager repos --enable=rhel-7-server-rpms # subscription-manager repos --enable=rhel-7-server-rh-common-rpms
- Install the cloud-init package and dependencies:
# yum install cloud-init
7.8.3. Using Cloud-Init to Prepare a Template
Note
Procedure 7.11. Using Cloud-Init to Prepare a Template
- Click the Virtual Machines tab and select a virtual machine.
- Click.
- Click the Initial Run tab and select the Use Cloud-Init/Sysprep check box.
- Enter a host name in the VM Hostname text field.
- Select the Configure Time Zone check box and select a time zone from the Time Zone drop-down list.
- Expand the Authentication section and select the Use already configured password check box to use the existing credentials, or clear that check box and enter a root password in the Password and Verify Password text fields to specify a new root password.
- Enter any SSH keys to be added to the authorized hosts file on the virtual machine in the SSH Authorized Keys text area.
- Select the Regenerate SSH Keys check box to regenerate SSH keys for the virtual machine.
- Expand the Networks section and enter any DNS servers in the DNS Servers text field.
- Enter any DNS search domains in the DNS Search Domains text field.
- Select the Network check box and use the and buttons to add or remove network interfaces to or from the virtual machine.
Important
You must specify the correct network interface name and number (for example,eth0
,eno3
,enp0s
). Otherwise, the virtual machine's interface connection will be up, but it will not have thecloud-init
network configuration. - Expand the Custom Script section and enter any custom scripts in the Custom Script text area.
- Click.
- Clickand enter the fields as necessary.
- Click.
7.8.4. Using Cloud-Init to Initialize a Virtual Machine
Procedure 7.12. Using Cloud-Init to Initialize a Virtual Machine
- Click the Virtual Machines tab and select a virtual machine.
- Click.
- Expand the Initial Run section and select the Cloud-Init check box.
- Enter a host name in the VM Hostname text field.
- Select the Configure Time Zone check box and select a time zone from the Time Zone drop-down menu.
- Select the Use already configured password check box to use the existing credentials, or clear that check box and enter a root password in the Password and Verify Password text fields to specify a new root password.
- Enter any SSH keys to be added to the authorized hosts file on the virtual machine in the SSH Authorized Keys text area.
- Select the Regenerate SSH Keys check box to regenerate SSH keys for the virtual machine.
- Enter any DNS servers in the DNS Servers text field.
- Enter any DNS search domains in the DNS Search Domains text field.
- Select the Network check box and use the + and - buttons to add or remove network interfaces to or from the virtual machine.
Important
You must specify the correct network interface name and number (for example,eth0
,eno3
,enp0s
). Otherwise, the virtual machine's interface connection will be up, but it will not have thecloud-init
network configuration. - Enter a custom script in the Custom Script text area. Make sure the values specified in the script are appropriate. Otherwise, the action will fail.
- Click.
Note