Ansible role for creating virtual machines based on Ubuntu Cloud Images in a vSphere environment.
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.
netplan
for network configuration.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.
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.
vcenter_hostname
or the environment variable VMWARE_HOST
.vcenter_username
or the environment variable VMWARE_USER
.vcenter_password
or the environment variable VMWARE_PASSWORD
.vcenter_validate_certs=no
or setting the environment variable
VMWARE_VALIDATE_CERTS
to no
.ova_file
.vmware_datacenter
on the datastore vmware_datastore
.vmware_folder
and in a resource pool by specifying vmware_resource_pool
.inventory_hostname
by default. It can be changed with vm_guestname
.inventory_hostname_short
by default. It can be changed with vm_hostname
.ssh_keys
to set a list of public keys that will be added to the authorized_keys file of the user "ubuntu".
At least one of ssh_keys
and password
has to be specified so that Ansible can connect to the new machine.password
to set a password for the user "ubuntu".
At least one of ssh_keys
and password
has to be specified so that Ansible can connect to the new machine.hardware
, containing a dictionary as specified in vmware_guest.disk
. This parameter accepts a list of disk specifications as documented in vmware_guest_disk.
The first disk corresponds to the imported virtual disk. Its size may only be increased.
See the example playbook below for usage.networks
, see vmware_deploy_ovf for semantics.annotation
.Virtual Machine > Configuration > Set annotation
is required.advanced_settings
with a list of dicts as shown in the example playbook. customvalues
with a list of dicts as show in the example playbook. Note that new custom values will not be created, they should exist in vCenter prior to deploying.To use a static IP address, use the following keys in the dictionary static_ip
:
ipv4
- a specific IPv4 address you want to assign. Defaults to the IPv4 address found in DNS for the FQDN.netmask
- the netmask in CIDR notation, defaults to 8
.gateway
- the default gateway (required)dns_servers
- a list of the DNS servers' IP addresses, defaults to Google's public DNS servers.dns_search
- a list of domain names that should be used as DNS search suffixes.
Use this to put your VM in a domain. 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
This role does not depend on other roles.
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
MIT
This role was created by Harald Albers at HS - Hamburger Software GmbH & Co. KG.