A multi-distro infrastructure automation project using Vagrant and Ansible to provision and configure a realistic multi-tier server environment across Rocky Linux and Ubuntu systems.
Built as a hands-on learning project demonstrating infrastructure-as-code principles, role-based Ansible structure, and cross-distribution configuration management.
Four virtual machines are provisioned automatically, each assigned a dedicated role:
| Hostname | IP | OS | Role |
|---|---|---|---|
ubuntu01 |
192.168.56.10 | Ubuntu 22.04 | Web Server |
ubuntu02 |
192.168.56.11 | Ubuntu 22.04 | Database Server |
rocky01 |
192.168.56.12 | Rocky Linux 8 | Web Server |
rocky02 |
192.168.56.13 | Rocky Linux 8 | File Server |
- Multi-distro support — handles package management, service names, and configuration differences between Rocky Linux (dnf) and Ubuntu (apt) automatically
- Role-based structure — clean separation of concerns across base, web, database, and file server roles
- group_vars — variables organized by group rather than per-host, keeping configuration DRY and scalable
- Idempotent playbooks — safe to run multiple times without unintended side effects
- Jinja2 templating — distro-specific SSH configuration generated from templates
- Tagged tasks — run specific parts of the playbook without executing everything
- Single entrypoint —
site.ymlorchestrates the full stack in the correct order
- Vagrant >= 2.3
- VirtualBox >= 6.1
- Ansible >= 2.12
- An SSH key pair at
~/.ssh/ansible(see Setup below)
Before running the playbooks, update group_vars/all.yml with your values:
admin_user: ansible
admin_ssh_key: "ssh-ed25519 YOUR_PUBLIC_KEY_HERE ansible"
server_admin_email: admin@example.comTo generate an SSH key for Ansible:
ssh-keygen -t ed25519 -C "ansible" -f ~/.ssh/ansible1. Clone the repository:
git clone https://github.com/zemation/ansible-learnlinux.git
cd ansible-learnlinux2. Update group_vars/all.yml with your SSH public key and email as shown above.
3. Start the VMs:
vagrant up4. Bootstrap the environment — creates the ansible service account, deploys the SSH key, and configures sudoers:
ansible-playbook bootstrap.yml5. Run the full playbook:
ansible-playbook site.ymlansible-learnlinux/
├── ansible.cfg # Ansible configuration (inventory, remote user, key)
├── Vagrantfile # VM definitions (4 nodes, Rocky + Ubuntu)
├── inventory # Host groups (web_servers, db_servers, file_servers)
├── bootstrap.yml # Initial setup — service account, SSH key, sudoers
├── site.yml # Main playbook — applies all roles in order
├── group_vars/
│ ├── all.yml # Global variables (admin user, SSH key, email)
│ ├── web_servers.yml # Web server package and service variables
│ ├── db_servers.yml # Database server SSH variables
│ └── file_servers.yml # File server SSH variables
├── files/
│ ├── default_site.html # Default web server index page
│ └── sudoer_ansible # Sudoers config for the ansible service account
└── roles/
├── base/ # Applied to all hosts — SSH hardening, service account
├── web_servers/ # Apache + PHP installation and configuration
├── db_servers/ # MariaDB installation and service management
└── file_servers/ # Samba installation and service management
Run the full stack:
ansible-playbook site.ymlRun only specific roles using tags:
ansible-playbook site.yml --tags apache # Web server tasks only
ansible-playbook site.yml --tags db # Database tasks only
ansible-playbook site.yml --tags samba # File server tasks only
ansible-playbook site.yml --tags ssh # SSH configuration onlyTarget a specific host:
ansible-playbook site.yml --limit 192.168.56.10Tear down the environment:
vagrant destroy -fApplied to all hosts. Deploys the Ansible service account SSH key and handles SSH hardening via distro-specific Jinja2 templates.
Installs and configures Apache and PHP using distribution-appropriate package names. Starts and enables the web service and deploys a default index page. Configures the ServerAdmin email on Rocky Linux.
Installs MariaDB using the correct package name for each distribution (mariadb on Rocky, mariadb-server on Ubuntu). Starts and enables the MariaDB service.
Installs Samba and starts and enables the service for file sharing.
- Upgrade Rocky Linux boxes to Rocky 9
- Wire web servers to query the database tier
- Add HAProxy load balancer node
- Add Kafka message broker as optional extension
- Add centralized logging (ELK/EFK) as optional extension
MIT