Install an Operating system via pxe boot and ansible

I have been using Ansible for a few days now. I would like to use Ansible to:

  1. perform a PXE boot of the target computer
  2. format the hard disk(s) of the target computer and delete the master boot record.
  3. install AlmaLinux as a workstation and change all settings, e.g.
    3.1. create a new user and assign the password
    3.2. set up the keybord settings.
    3.x etc

Who has already realized such a project and would like to give me some tips?

I am grateful for any help.

Is this for physical servers/workstations or VMs?

I have both physical servers/workstations and VM’s. What makes the difference?

Even though I like Ansible a lot, if the target platform is Alma/Rocky/Fedora/CentOS/RHEL, why don’t just use kickstart? It basically does everything you could possible want already out of the box. And if you want it more managed/special, look towards Foreman/Katello or RH Satellite Server.

Also, when installing systems, physical or virtual (in which you can also use tools like Packer to build templates for you, they also use kickstart in the case of EL-family), keep in mind that less is more.

In my case, when I provision a new Linux system, I do the bare minimum in the template to make it ‘compatible’ with the rest of my automation code. I generally do the following things:

  • Install a minimum installation of the desired OS
  • Set up disk partitioning according to company policy
  • Add a user with sudo privileges and the SSH key of your existing Ansible control node

And when a system has been deployed with the above template:

  • Run automation ‘as usual’ to bring the system’s configuration in line with policy
  • Install updates
  • Reboot

This way, you have a ‘standard’ building block that will be the same, no matter what. You can even, if your automation code is set up for it, go from zero to production system within an hour (depending on installation size, yada, yada, yada)

1 Like

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.

2 Likes