hamburger-software / ansible-role-vmware_ubuntu_cloud_image

Ansible role for creating virtual machines based on the Ubuntu Cloud Image in a vSphere environment.
https://galaxy.ansible.com/hamburger_software/vmware_ubuntu_cloud_image
MIT License
19 stars 7 forks source link
ansible ansible-role deployment devops vmware vsphere

vmware_ubuntu_cloud_image

Ansible role for creating virtual machines based on Ubuntu Cloud Images in a vSphere environment.

Ubuntu Cloud Images

Ubuntu offers pre-installed images for usage in clouds. One of the available image formats is Open Virtualization Appliance (OVA) that can be imported into VMware. The images use the cloud-init mechanism to allow very basic configuration. Sadly, there is no support for using static IP addresses and for adjusting the hardware during machine creation.

This role adds support for these features.

Features

Requirements

To use this role, you need

If you want to retrieve the VM's IP addresses from DNS, you also have to

The minimum Ansible version is 2.10.7. The minimum community.vmware collection version is 1.8.0, which is part of the Ansible community package 3.2.0.

vSphere Permissions

The minimum permissions to create a VM with this role are:

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 adjust CPU and memory settings, you need

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

To adjust disk size, you need

Virtual Machine > Configuration > Extend virtual disk

Advanced configuration options might need additional privileges.

Role Variables

vCenter Connection

VMware Settings

VM Settings

To use a static IP address, use the following keys in the dictionary static_ip:

Inventory Settings

As the VMs do not exist yet, the ssh server's key is unknown. In order to connect to the new VMs, you need to turn off ssh host key checking. If you plan to frequently recreate VMs with the same FQDNs, ssh should not store the fingerprints in the _knownhosts file.

Therefore, the recommended host/group variables are:

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

Dependencies

This role does not depend on other roles.

Example Playbook

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: Administrator@vsphere.local
        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'
        # this avoids excessive syslog messages from multipathd under Ubuntu 20.04
        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 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.