Ansible Infrastructure Evolution: A Structured Approach to Configuration Management
Overview
As our infrastructure grows, we need a more structured and maintainable approach to configuration management. This post outlines our plan to evolve our Ansible setup to better handle different Ubuntu versions, architectures, and machine types while maintaining simplicity and reusability.
Current State
Our current Ansible setup has served us well but faces several challenges:
- Mixed concerns in inventory structure
- Inconsistent variable management
- Limited role reusability
- Manual tracking of OS versions and architectures
New Approach
1. Hierarchical Inventory Structure
We've implemented a new inventory structure that clearly separates hosts based on:
- Ubuntu version (22.04, 24.04)
- Architecture (ARM, x86)
- Machine type (server, workstation, laptop)
all:
children:
ubuntu22:
children:
ubuntu22_arm:
children:
servers_22_arm:
workstations_22_arm:
laptops_22_arm:
ubuntu22_x86:
# Similar structure
ubuntu24:
# Similar structure
2. Layered Variable Management
Variables are now organized in layers:
-
Global Variables (
group_vars/all.yml)- Common packages
- Python setup
- Security defaults
- System locale/timezone
-
OS Version Variables (
group_vars/ubuntu22.yml,group_vars/ubuntu24.yml)- Version-specific packages
- Kernel parameters
- System configurations
-
Architecture Variables (
group_vars/ubuntu22_arm.yml, etc.)- Architecture-specific optimizations
- Binary paths
- Compiler flags
-
Role Variables (
group_vars/servers.yml, etc.)- Role-specific configurations
- Service settings
- Security policies
3. Role-Based Configuration
Roles are now tagged with clear purposes:
- Base roles (common, security)
- Machine-type roles (server, workstation, laptop)
- Service roles (docker, development, monitoring)
Implementation Plan
Phase 1: Foundation (Week 1-2)
- Implement new inventory structure
- Create base group_vars files
- Update common roles for new structure
- Add validation for host categorization
Phase 2: Role Refactoring (Week 3-4)
- Split roles by machine type
- Implement role dependencies
- Add role documentation
- Create role test playbooks
Phase 3: Variable Management (Week 5-6)
- Implement layered variables
- Add variable validation
- Create variable documentation
- Set up defaults hierarchy
Phase 4: Testing & Documentation (Week 7-8)
- Create test scenarios
- Implement CI/CD for Ansible
- Write comprehensive documentation
- Create playbook examples
Benefits
- Clarity: Clear separation of concerns in inventory
- Maintainability: Structured variable management
- Reusability: Well-defined roles and playbooks
- Scalability: Easy addition of new hosts and configurations
- Testability: Improved testing capabilities
Migration Strategy
- Start with new hosts using the new structure
- Gradually migrate existing hosts
- Use tags for selective execution
- Maintain backward compatibility
- Document all changes
Next Steps
- Complete Phase 1 implementation
- Review and update existing roles
- Begin role refactoring
- Set up testing framework
Conclusion
This structured approach to Ansible configuration management will help us maintain a clean, efficient, and scalable infrastructure. The clear separation of concerns and layered variable management will make it easier to add new hosts and configurations while maintaining existing ones.
Tags
#ansible #infrastructure #devops #configuration-management