hamburger_software.vmware_ubuntu_cloud_image

vmware_ubuntu_cloud_image

=========================

This is an Ansible role that helps create virtual machines using Ubuntu Cloud Images in a vSphere setup.

Ubuntu Cloud Images

Ubuntu provides ready-to-use images for cloud environments. One format is the Open Virtualization Appliance (OVA), which can be imported into VMware. These images use cloud-init for basic configuration. Unfortunately, they do not support static IP addresses or hardware adjustments during VM creation.

This role adds those missing features.

Features

  • Create a VM from a downloaded OVA file.
  • Set the hostname.
  • Add one or more SSH public keys and/or a password for the default user "ubuntu" to enable Ansible access.
  • Optionally change hardware settings, like the number of CPUs or memory. See vmware_guest for details.
  • Add VM notes (annotations), adjust VM configuration parameters, and/or set VM custom attributes.
  • Increase disk size from the default 10GB or add more disks.
  • Optionally change the dynamic IP address to a static one.
  • Start the VM and use it in the same playbook.
  • Create multiple VMs at once.
  • Compatible with Ubuntu Cloud Images like 21.04, 20.10, and others.

Note: Older versions may not work because they don’t use netplan for network setup.

Requirements

To use this role, you need:

If you want to get the VM's IP addresses from DNS, you must also:

  • Install dnspython (a Python library).
  • Use fully qualified domain names (FQDN, e.g., host.example.org) in your inventory.
  • Add DNS A records for each VM you create.

Minimum Ansible version: 2.10.7. Minimum community.vmware collection version: 1.8.0.

vSphere Permissions

You need the following permissions to create a VM:

  • DataStore > Allocate Space
  • Network > Assign Network
  • Resource > Assign Virtual Machine to Resource Pool
  • vApp > Import
  • Virtual Machine > Interaction > Power On
  • Virtual Machine > Configuration > Add New Disk

To change CPU and memory settings:

  • Virtual Machine > Configuration > Change CPU count
  • Virtual Machine > Configuration > Memory

To adjust the disk size:

  • Virtual Machine > Configuration > Extend virtual disk

Advanced options may require more permissions.

Role Variables

vCenter Connection

  • Set the vCenter server URL with vcenter_hostname or VMWARE_HOST.
  • Set the vCenter username with vcenter_username or VMWARE_USER.
  • Set the vCenter password with vcenter_password or VMWARE_PASSWORD.
  • You can disable certificate validation with vcenter_validate_certs=no or set VMWARE_VALIDATE_CERTS to no.

VMware Settings

  • Specify the OVA file on the control machine with ova_file.
  • Create the VM in the datacenter defined by vmware_datacenter on the datastore specified by vmware_datastore.
  • Place the VM in a folder and resource pool if needed.
  • The VM name defaults to the inventory_hostname but can be changed with vm_guestname.

VM Settings

  • Default hostname is inventory_hostname_short, which can be changed with vm_hostname.
  • Use ssh_keys to set public keys for the "ubuntu" user.
  • Use password for the "ubuntu" user.
  • Adjust hardware with hardware.
  • Change disk size with disk, but the first disk's size can only be increased.
  • Define network mappings with networks.
  • Set VM notes with annotation.
  • Specify VM configuration parameters with advanced_settings.
  • Set custom attributes with customvalues, which should already exist in vCenter.

For static IP, use the static_ip dictionary:

  • ipv4: the specific address you want.
  • netmask: the netmask in CIDR notation.
  • gateway: the required default gateway.
  • dns_servers: a list of DNS servers.
  • dns_search: domain names for search suffixes.

Inventory Settings

Since the VMs don’t exist yet, you need to disable SSH host key checking. This avoids issues if you recreate VMs with the same FQDNs.

Recommended settings:

ansible_user=ubuntu
ansible_ssh_extra_args=-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null

Dependencies

This role does not depend on any other roles.

Example Playbook

- name: Deploy a Ubuntu Cloud Image Virtual Appliance
  hosts: cloudimg
  gather_facts: no

  roles:
    - role: hamburger_software.vmware_ubuntu_cloud_image
      vars:
        vcenter_hostname: vcenter.your.domain
        vcenter_username: [email protected]
        vcenter_password: verysecret
        vcenter_validate_certs: no
        vmware_datacenter: your-datacenter
        vmware_datastore: your-datastore
        vmware_folder: your-datacenter/vm/some-folder
        ova_file: ubuntu-20.04-server-cloudimg-amd64.ova
        hardware:
          num_cpus: 4
          memory_mb: 2048
        annotation: 'Sample VM based on Ubuntu Cloud Image'
        advanced_settings:
          - key: disk.EnableUUID
            value: 'TRUE'
        customvalues:
          - key: 'yourkey'
            value: 'yourvalue'
        disk:
          - size_gb: 20
            datastore: your-datastore
            scsi_controller: 0
            unit_number: 0
          - size_mb: 250
            datastore: your-datastore
            scsi_controller: 0
            unit_number: 1
            type: thin
        static_ip:
          netmask: 16
          gateway: 10.0.42.1
          dns_servers: [10.0.47.11, 10.0.48.12]
          dns_search:
          - your.domain
        ssh_keys:
          - ssh-rsa AAAAB3Nz[...] some-key-name
        password: passw0rd

Inventory example with 5 hosts:

[cloudimg]
vm-[1:5].your.domain

[cloudimg:vars]
ansible_user=ubuntu
ansible_password=passw0rd
ansible_ssh_extra_args=-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null

License

MIT

Author Information

This role was created by Harald Albers at HS - Hamburger Software GmbH & Co. KG.

Informazioni sul progetto

Creates virtual machines based on Ubuntu Cloud Images in a vSphere environment.

Installa
ansible-galaxy install hamburger_software.vmware_ubuntu_cloud_image
Licenza
mit
Download
732
Proprietario
Product documentation and open source projects created at HS - Hamburger Software GmbH & Co. KG