|
| 1 | +# DHCP Options Support in libvirt_manager |
| 2 | + |
| 3 | +This document explains how to add DHCP options to VM groups in the libvirt_manager role. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The libvirt_manager role now supports assigning DHCP options to groups of VMs based on their type. This is useful for scenarios like PXE booting where you need to provide specific boot parameters to certain VM types. |
| 8 | + |
| 9 | +## How It Works |
| 10 | + |
| 11 | +1. **VM Type Tagging**: Each VM is automatically tagged with its type (e.g., `compute`, `controller`, `baremetal_instance`) |
| 12 | +2. **DHCP Options**: You can specify DHCP options in the VM type definition |
| 13 | +3. **dnsmasq Configuration**: The role automatically generates dnsmasq configuration that applies these options to all VMs of that type |
| 14 | + |
| 15 | +## Configuration Example |
| 16 | + |
| 17 | +### Basic Example |
| 18 | + |
| 19 | +Here's how to add DHCP options for PXE booting to baremetal instances: |
| 20 | + |
| 21 | +```yaml |
| 22 | +cifmw_libvirt_manager_configuration: |
| 23 | + vms: |
| 24 | + baremetal_instance: |
| 25 | + amount: 3 |
| 26 | + disk_file_name: "blank" |
| 27 | + disksize: 50 |
| 28 | + memory: 8 |
| 29 | + cpus: 4 |
| 30 | + bootmenu_enable: "yes" |
| 31 | + nets: |
| 32 | + - public |
| 33 | + - provisioning |
| 34 | + dhcp_options: |
| 35 | + - "60,HTTPClient" # Vendor class identifier |
| 36 | + - "67,http://192.168.122.1:8081/boot.ipxe" # Boot filename (iPXE script) |
| 37 | +``` |
| 38 | +
|
| 39 | +### Advanced Example with Multiple VM Types |
| 40 | +
|
| 41 | +```yaml |
| 42 | +cifmw_libvirt_manager_configuration: |
| 43 | + vms: |
| 44 | + controller: |
| 45 | + amount: 1 |
| 46 | + image_url: "{{ cifmw_discovered_image_url }}" |
| 47 | + sha256_image_name: "{{ cifmw_discovered_hash }}" |
| 48 | + disk_file_name: "centos-stream-9.qcow2" |
| 49 | + disksize: 50 |
| 50 | + memory: 4 |
| 51 | + cpus: 2 |
| 52 | + nets: |
| 53 | + - public |
| 54 | + - osp_trunk |
| 55 | + # No DHCP options for controllers - they'll use defaults |
| 56 | + |
| 57 | + compute: |
| 58 | + amount: 3 |
| 59 | + disk_file_name: blank |
| 60 | + disksize: 40 |
| 61 | + memory: 8 |
| 62 | + cpus: 4 |
| 63 | + nets: |
| 64 | + - public |
| 65 | + - osp_trunk |
| 66 | + dhcp_options: |
| 67 | + - "60,HTTPClient" |
| 68 | + - "67,http://192.168.122.1:8081/boot-artifacts/compute-boot.ipxe" |
| 69 | + |
| 70 | + baremetal_instance: |
| 71 | + amount: 2 |
| 72 | + disk_file_name: "blank" |
| 73 | + disksize: 50 |
| 74 | + memory: 8 |
| 75 | + cpus: 4 |
| 76 | + bootmenu_enable: "yes" |
| 77 | + nets: |
| 78 | + - public |
| 79 | + dhcp_options: |
| 80 | + - "60,HTTPClient" |
| 81 | + - "67,http://192.168.122.1:8081/boot-artifacts/agent.x86_64.ipxe" |
| 82 | +``` |
| 83 | +
|
| 84 | +## Common DHCP Options |
| 85 | +
|
| 86 | +Here are some commonly used DHCP options for PXE/network booting: |
| 87 | +
|
| 88 | +| Option | Name | Purpose | Example | |
| 89 | +|--------|------|---------|---------| |
| 90 | +| 60 | vendor-class-identifier | Identifies the vendor/client type | `60,HTTPClient` | |
| 91 | +| 67 | bootfile-name | Path to boot file | `67,http://server/boot.ipxe` | |
| 92 | +| 66 | tftp-server-name | TFTP server address | `66,192.168.1.10` | |
| 93 | +| 150 | tftp-server-address | TFTP server IP (Cisco) | `150,192.168.1.10` | |
| 94 | +| 210 | path-prefix | Path prefix for boot files | `210,/tftpboot/` | |
| 95 | + |
| 96 | + |
| 97 | +## Technical Details |
| 98 | + |
| 99 | +### Under the Hood |
| 100 | + |
| 101 | +1. **Tag Assignment**: When VMs are created, each is assigned a tag matching its type in the dnsmasq DHCP host entry: |
| 102 | + ``` |
| 103 | + set:baremetal_instance,52:54:00:xx:xx:xx,192.168.122.10,hostname |
| 104 | + ``` |
| 105 | + |
| 106 | +2. **DHCP Options Configuration**: A configuration file is generated at `/etc/cifmw-dnsmasq.d/vm-types-dhcp-options.conf`: |
| 107 | + ``` |
| 108 | + # Options for baremetal_instance VMs |
| 109 | + dhcp-option=tag:baremetal_instance,60,HTTPClient |
| 110 | + dhcp-option=tag:baremetal_instance,67,http://192.168.122.1:8081/boot.ipxe |
| 111 | + ``` |
| 112 | + |
| 113 | +3. **dnsmasq Processing**: When a VM with the `baremetal_instance` tag requests DHCP, it receives both the standard network options AND the VM-type-specific options. |
| 114 | + |
| 115 | +### Files Modified |
| 116 | + |
| 117 | +- `roles/libvirt_manager/tasks/reserve_dnsmasq_ips.yml`: Adds VM type tags to DHCP entries |
| 118 | +- `roles/libvirt_manager/tasks/create_dhcp_options.yml`: New file that generates DHCP options configuration |
| 119 | +- `roles/libvirt_manager/tasks/generate_networking_data.yml`: Includes the new task |
| 120 | +- `roles/dnsmasq/tasks/manage_host.yml`: Updated to support tags in DHCP entries |
| 121 | + |
| 122 | +## Troubleshooting |
| 123 | + |
| 124 | +### Verify DHCP Options Are Applied |
| 125 | + |
| 126 | +1. Check the generated configuration: |
| 127 | + ```bash |
| 128 | + cat /etc/cifmw-dnsmasq.d/vm-types-dhcp-options.conf |
| 129 | + ``` |
| 130 | + |
| 131 | +2. Check DHCP host entries: |
| 132 | + ```bash |
| 133 | + ls -la /etc/cifmw-dnsmasq.d/dhcp-hosts.d/ |
| 134 | + cat /etc/cifmw-dnsmasq.d/dhcp-hosts.d/public_* |
| 135 | + ``` |
| 136 | + |
| 137 | +3. Verify dnsmasq configuration is valid: |
| 138 | + ```bash |
| 139 | + dnsmasq -C /etc/cifmw-dnsmasq.conf --test |
| 140 | + ``` |
| 141 | + |
| 142 | +4. Monitor DHCP requests: |
| 143 | + ```bash |
| 144 | + journalctl -u cifmw-dnsmasq -f |
| 145 | + ``` |
| 146 | + |
| 147 | +### Common Issues |
| 148 | + |
| 149 | +**Issue**: DHCP options not being sent to VMs |
| 150 | +- **Solution**: Ensure dnsmasq service is restarted after making changes |
| 151 | +- **Check**: Verify the VM type tag matches between the DHCP host entry and the options configuration |
| 152 | + |
| 153 | +**Issue**: VMs not PXE booting correctly |
| 154 | +- **Solution**: Verify the boot file URL is accessible from the VM's network |
| 155 | +- **Check**: Ensure option 67 contains the full URL including protocol (http://) |
| 156 | + |
| 157 | +## References |
| 158 | + |
| 159 | +- [dnsmasq manual](http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html) |
| 160 | +- [DHCP Options RFC](https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml) |
| 161 | +- [iPXE documentation](https://ipxe.org/howto/dhcpd) |
| 162 | + |
0 commit comments