It almost makes all the difference.
VMs can be controlled with Ansible by using VM platform specific modules like vmware_guest*
, xenserver_guest*
, ovirt_vm*
, or cloud specific like ec2*
, openstack.cloud.server*
etc. With physical machines you need some kind of out of band management capability like iLO (HP), iDRAC (Dell) and similar. Last time I experimented with this, Ansible modules for controlling life cycle of physical machines were not mature enough for my requirements. Maybe you will have more luck.
Anyway, if we take only VMs into consideration, here is what you need:
- DHCP server
- TFTP server
- pxelinux bootloader (for legacy BIOS) and grub bootloader (for UEFI) binaries hosted on TFTP server
- kernel and initrd of desired OS hosted on TFTP server
- HTTP server
- kickstart files hosted on HTTP server
- OS installations (unpacked ISOs) hosted on HTTP server
- VM platform supported by Ansible
The workflow would then be:
- Ansible creates a new (empty) VM and gets MAC address of newly created VM. Network interface should be connected to DHCP network.
- Ansible generates specific pxeboot or grub configuration file for that particular VM using MAC and uploads it to the TFTP server. Bootloader configuration should specify the kernel and the initrd from TFTP server, URL to OS installer and URL to kickstart file on HTTP server.
- You create a kickstart file that specify all the installation details including partitioning scheme, users, keyboard layout, timezone, packages etc. and upload it to HTTP server. This could be also automated via Ansible.
- Ansible boots the VM using network boot and waits for the VM to shutdown after OS installation. PXE boot and kickstart file should automate this part in entirety.
- Ansible can boot VM from HDD this time and run additional roles and/or tasks to additionally configure the VM.
- When this is done, you will have your VM ready.
This is a pure Ansible solution. Some parts could be done using Packer instead.