Skip to content

zemation/ansible-learnlinux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ansible-learnlinux

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.


Architecture

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

Features

  • 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 entrypointsite.yml orchestrates the full stack in the correct order

Prerequisites


Configuration

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.com

To generate an SSH key for Ansible:

ssh-keygen -t ed25519 -C "ansible" -f ~/.ssh/ansible

Setup

1. Clone the repository:

git clone https://github.com/zemation/ansible-learnlinux.git
cd ansible-learnlinux

2. Update group_vars/all.yml with your SSH public key and email as shown above.

3. Start the VMs:

vagrant up

4. Bootstrap the environment — creates the ansible service account, deploys the SSH key, and configures sudoers:

ansible-playbook bootstrap.yml

5. Run the full playbook:

ansible-playbook site.yml

Project Structure

ansible-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

Usage

Run the full stack:

ansible-playbook site.yml

Run 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 only

Target a specific host:

ansible-playbook site.yml --limit 192.168.56.10

Tear down the environment:

vagrant destroy -f

Roles

base

Applied to all hosts. Deploys the Ansible service account SSH key and handles SSH hardening via distro-specific Jinja2 templates.

web_servers

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.

db_servers

Installs MariaDB using the correct package name for each distribution (mariadb on Rocky, mariadb-server on Ubuntu). Starts and enables the MariaDB service.

file_servers

Installs Samba and starts and enables the service for file sharing.


Roadmap

  • 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

License

MIT

About

Multi-distro infrastructure automation using Vagrant and Ansible — provisions and configures web, database, and file servers across Rocky Linux and Ubuntu environments.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors