ADR-0003: Dynamic Configuration Management with Python
Status
Accepted
Context
Qubinode Navigator needed to automatically discover and configure network interfaces, storage devices, and system parameters across diverse hardware configurations and cloud environments. Manual configuration would be error-prone and time-consuming, especially when deploying across different cloud providers with varying network topologies, storage options, and system capabilities. The project required an intelligent configuration system that could adapt to different environments while maintaining consistency and reliability.
Decision
Implement dynamic configuration management using Python scripts that automatically discover system resources and generate environment-specific Ansible inventory configurations. The primary tool is load-variables.py, which performs network interface discovery, storage device detection, and system parameter configuration, then updates the appropriate inventory files with discovered values.
Consequences
Positive Consequences
- Eliminates manual configuration errors and reduces deployment time
- Automatically adapts to different hardware and cloud configurations
- Provides consistent configuration discovery across all supported environments
- Reduces the barrier to entry for new deployments
- Enables automated validation of system requirements
- Facilitates rapid environment provisioning and scaling
Negative Consequences
- Adds Python dependency and complexity to the deployment process
- Requires error handling for edge cases in hardware/network detection
- May fail in unusual or unsupported hardware configurations
- Debugging configuration issues requires Python knowledge
- Potential for incorrect auto-detection in complex network setups
Alternatives Considered
- Manual configuration files - Rejected due to error-prone nature and maintenance overhead
- Ansible facts gathering only - Insufficient for complex network and storage configuration
- Shell script-based discovery - Python chosen for better data manipulation and YAML handling
- Cloud-provider specific tools - Would create vendor lock-in and inconsistency
- Configuration management databases - Too complex for the project’s requirements
Evidence Supporting This Decision
load-variables.pyperforms comprehensive system discovery and configuration- Network interface detection using
netifaceslibrary for cross-platform compatibility - Storage device discovery with
psutilfor system resource information - Dynamic YAML file updates for inventory configuration
- Interactive prompts with validation for critical parameters
- Integration with multiple inventory environments
Implementation Details
Network Discovery
# From load-variables.py
def get_interface_ips(configure_bridge=None, interface=None):
addrs = netifaces.ifaddresses(interface)
ip = addrs[netifaces.AF_INET][0]['addr']
netmask = addrs[netifaces.AF_INET][0]['netmask']
macaddr = addrs[netifaces.AF_LINK][0]['addr']
Storage Configuration
def select_disk(disks=None):
# Automatic disk detection and selection
# Updates inventory with storage configuration
inventory['kvm_host_libvirt_extra_disk'] = disks
Dynamic Inventory Updates
def update_inventory(username=None, domain_name=None, dnf_forwarder=None):
inventory_path = 'inventories/'+str(inventory_env)+'/group_vars/all.yml'
with open(inventory_path, 'r') as f:
inventory = yaml.safe_load(f)
# Update with discovered values
Key Dependencies
netifaces: Cross-platform network interface informationpsutil: System and process utilitiesfire: Command-line interface generationrequests: HTTP library for API interactions
Configuration Flow
- System Detection: Discover network interfaces, storage devices, system capabilities
- User Interaction: Prompt for environment-specific parameters with validation
- Inventory Update: Generate and update YAML configuration files
- Validation: Verify configuration consistency and completeness
Integration Points
- Called by
setup.shduring initial environment setup - Supports both interactive and automated (CI/CD) modes
- Updates multiple inventory files based on environment selection
- Integrates with Ansible variable hierarchy
Related Decisions
- ADR-0001: Container-First Execution Model with Ansible Navigator
- ADR-0002: Multi-Cloud Inventory Strategy with Environment-Specific Configurations
- ADR-0004: Security Architecture with Ansible Vault (planned)
Date
2025-01-09
Stakeholders
- DevOps Team
- Infrastructure Team
- System Administrators
- Project Maintainers