A hands-on infrastructure automation, Linux security, database engineering, monitoring, and migration lab built on Ubuntu Server, KVM/libvirt, Terraform, Ansible, GitHub, and Python.
The project is designed to reproduce the engineering principles used in a large enterprise environment through a smaller representative lab.
Every push and pull request runs terraform fmt -check, terraform validate, tflint and ansible-lint (see .github/workflows/ci.yml). The Terraform job generates a throwaway SSH key because the lab reads ~/.ssh/lab_ed25519.pub at plan time; no credentials or state are used.
This lab demonstrates practical experience with:
- Linux systems administration
- Virtualisation with KVM, QEMU, and libvirt
- Infrastructure as Code with Terraform
- Configuration management with Ansible
- Secure server baseline automation
- Git-based change control
- Database deployment and security
- Database migration planning and validation
- Monitoring, logging, and auditing
- CI/CD orchestration
- Failure recovery and operational documentation
The final objective is to simulate an enterprise database migration and security platform using a small number of virtual machines and a larger generated application and database inventory.
Dell OptiPlex 7050
Ubuntu Server 24.04 LTS
│
├── KVM
├── QEMU
├── libvirt
├── Terraform
├── Ansible
├── Git
│
├── libvirt default NAT network
│ └── 192.168.122.0/24
│
├── lab-test-01
│ ├── Manually created reference VM
│ ├── Ubuntu Server 24.04
│ └── 192.168.122.125
│
└── tf-test-01
├── Terraform-managed VM
├── Ubuntu Server 24.04
├── 2 vCPUs
├── 2 GiB RAM
├── 20 GiB QCOW2 disk
├── Cloud-init configuration
└── 192.168.122.151
Terraform configuration
↓
libvirt provider
↓
KVM virtual machine
↓
Cloud-init bootstrap
↓
Terraform IP output
↓
Inventory-generation script
↓
Ansible inventory
↓
Linux security baseline
↓
Validation and idempotency testing
- Installed Ubuntu Server 24.04 LTS on the physical Dell host
- Verified Intel VT-x hardware virtualisation
- Verified access to
/dev/kvm - Installed KVM, QEMU, libvirt, and supporting tools
- Configured the default libvirt NAT network
- Configured the default libvirt storage pool
- Verified DHCP, DNS, routing, and internet access
- Configured SSH and Tailscale access to the host
- Downloaded and verified an Ubuntu cloud image
- Created a manually managed QCOW2 virtual machine
- Configured cloud-init
- Configured SSH public-key authentication
- Tested VM lifecycle operations
- Inspected libvirt XML, disks, interfaces, and networking
- Recovered a VM definition while preserving its disk and data
- Installed Terraform from the HashiCorp repository
- Configured the
dmacvicar/libvirtprovider - Imported a reusable Ubuntu QCOW2 base image
- Created a thin-provisioned QCOW2 overlay disk
- Generated a cloud-init ISO
- Created and started a libvirt domain
- Connected the VM to the default NAT network
- Retrieved DHCP interface information
- Exposed the Terraform-managed VM IP as an output
- Verified Terraform state
- Verified Terraform idempotency
A successful Terraform plan currently returns:
No changes. Your infrastructure matches the configuration.
- Initialised a Git repository
- Added a secure
.gitignore - Excluded Terraform state, plans, provider files, images, and secrets
- Added commit identity using a GitHub no-reply address
- Created a private GitHub repository
- Pushed the
mainbranch - Maintained incremental commits for each working milestone
- Installed Ansible Core
- Created a project-specific
ansible.cfg - Created a YAML inventory
- Configured SSH-agent authentication
- Verified Ansible connectivity with the
pingmodule - Gathered operating-system facts
- Created a verification playbook
- Created a reusable
linux_baselinerole - Added environment-specific variables through
group_vars - Added modular task files and tags
- Generated the Ansible inventory from Terraform output
- Tested Ansible check mode
- Verified Ansible idempotency
A repeated baseline run currently returns:
changed=0
unreachable=0
failed=0
The Terraform configuration manages:
- Ubuntu cloud base image
- Terraform-managed QCOW2 overlay disk
- Cloud-init ISO
- libvirt virtual machine domain
- CPU and memory allocation
- Virtual network interface
- DHCP address lookup
- Terraform outputs
The environment is stored under:
terraform/environments/lab/
cd terraform/environments/lab
terraform fmt
terraform validate
terraform plan
terraform apply
terraform outputTo retrieve only the Terraform-managed VM IP:
terraform output -raw tf_test_01_ipTerraform can also be used from the repository root:
terraform -chdir=terraform/environments/lab planTerraform retrieves the VM address through the libvirt DHCP lease data source.
The inventory-generation script reads the Terraform output and writes the current address into the Ansible inventory.
Run:
./scripts/generate-ansible-inventory.shExample output:
Generated Ansible inventory:
VM: tf-test-01
IP: 192.168.122.151
File: ansible/inventories/lab/hosts.yml
This removes the need to manually search for the VM address with virsh.
The linux_baseline role applies a reusable security and administration baseline to Terraform-managed Ubuntu virtual machines.
The role ensures the following packages are present:
auditdca-certificatescurlgithtopjqufwunzipvim
The role ensures:
auditdis enabled and runningsystemd-timesyncdis enabled and running- The system clock is synchronized
- The server uses UTC
The role manages an OpenSSH drop-in configuration:
/etc/ssh/sshd_config.d/00-linux-baseline.conf
The effective SSH security settings include:
Port 22
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
X11Forwarding no
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
The SSH configuration is validated with:
/usr/sbin/sshd -tThe SSH service is restarted through an Ansible handler only when the managed configuration changes.
The deployment process is designed to reduce lockout risk:
Render configuration
↓
Validate candidate configuration
↓
Install managed configuration
↓
Validate full SSH configuration
↓
Restart SSH through handler
↓
Test a new Ansible connection
The baseline manages UFW using the community.general.ufw module.
The firewall configuration includes:
- Allow SSH on TCP port 22
- Deny incoming traffic by default
- Allow outgoing traffic by default
- Enable low-level firewall logging
- Enable UFW
The SSH allow rule is created before UFW is enabled.
Current firewall status:
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing)
22/tcp ALLOW IN
The lab environment variables are stored in:
ansible/inventories/lab/group_vars/all.yml
They include:
linux_baseline_timezone: Etc/UTC
linux_baseline_environment: Lab
linux_baseline_ssh_port: 22
linux_baseline_manage_firewall: true
linux_baseline_motd_title: Enterprise Database Migration and Security LabThe role also contains reusable defaults.
Firewall management is disabled by default in the role and explicitly enabled by the lab inventory.
The role supports selective execution through tags:
packages
services
ssh
security
firewall
Examples:
ansible-playbook playbooks/linux-baseline.yml --tags packages
ansible-playbook playbooks/linux-baseline.yml --tags services
ansible-playbook playbooks/linux-baseline.yml --tags ssh
ansible-playbook playbooks/linux-baseline.yml --tags firewall
ansible-playbook playbooks/linux-baseline.yml --tags securityGenerate the current inventory:
./scripts/generate-ansible-inventory.shEnter the Ansible directory:
cd ansibleVerify the inventory:
ansible-inventory --graph
ansible-inventory --host tf-test-01Test connectivity:
ansible terraform_vms -m pingCheck playbook syntax:
ansible-playbook playbooks/linux-baseline.yml --syntax-checkPreview changes:
ansible-playbook playbooks/linux-baseline.yml --checkApply the baseline:
ansible-playbook playbooks/linux-baseline.ymlRun it again to verify idempotency:
ansible-playbook playbooks/linux-baseline.ymlExpected second-run recap:
changed=0
unreachable=0
failed=0
The project uses:
community.general 8.3.0
Dependencies are recorded in:
ansible/collections/requirements.yml
Install them with:
cd ansible
ansible-galaxy collection install \
-r collections/requirements.yml.
├── .gitignore
├── README.md
│
├── terraform/
│ └── environments/
│ └── lab/
│ ├── cloud-init/
│ │ ├── meta-data.yaml.tftpl
│ │ └── user-data.yaml.tftpl
│ ├── .terraform.lock.hcl
│ ├── cloudinit.tf
│ ├── domain.tf
│ ├── locals.tf
│ ├── provider.tf
│ ├── read-only.tf
│ ├── variables.tf
│ ├── versions.tf
│ └── volumes.tf
│
├── ansible/
│ ├── ansible.cfg
│ ├── collections/
│ │ └── requirements.yml
│ ├── inventories/
│ │ └── lab/
│ │ ├── hosts.yml
│ │ └── group_vars/
│ │ └── all.yml
│ ├── playbooks/
│ │ ├── verify.yml
│ │ └── linux-baseline.yml
│ └── roles/
│ └── linux_baseline/
│ ├── defaults/
│ │ └── main.yml
│ ├── handlers/
│ │ └── main.yml
│ ├── tasks/
│ │ ├── main.yml
│ │ ├── packages.yml
│ │ ├── services.yml
│ │ ├── ssh.yml
│ │ └── firewall.yml
│ └── templates/
│ └── 00-linux-baseline.conf.j2
│
└── scripts/
└── generate-ansible-inventory.sh
The repository excludes sensitive and generated files, including:
- Terraform state
- Terraform state backups
- Terraform plan files
- Terraform provider binaries
- Private SSH keys
- Environment files
- Virtual-machine disk images
- ISO installation files
- Ansible Vault password files
- Credentials and tokens
The following files must never be committed:
*.tfstate
*.tfstate.*
*.tfvars
*.plan
.env
*.pem
*.key
id_rsa
id_ed25519
vault-password*
Before committing, the repository can be checked with:
git diff --checkA basic secret scan can also be performed:
grep -RInE \
'BEGIN .*PRIVATE KEY|gho_|github_pat_|password[[:space:]]*=|token[[:space:]]*=|secret[[:space:]]*=' \
. \
--exclude-dir=.git \
--exclude-dir=.terraform \
--exclude='*.tfstate' \
--exclude='*.tfstate.*' \
--exclude='*.plan'This project follows several enterprise engineering principles.
Virtual-machine configuration is declared in Terraform rather than manually recreated.
Linux security and operating-system settings are managed through Ansible roles and playbooks.
Repeated Terraform and Ansible runs produce no changes when the environment already matches the desired state.
Terraform
└── Provisions infrastructure
Cloud-init
└── Performs first-boot configuration
Ansible
└── Applies and maintains operating-system configuration
GitHub
└── Stores code and change history
Jenkins
└── Will orchestrate the complete workflow
- Terraform plans are reviewed before applying
- Ansible check mode is used before deployment
- SSH configurations are validated before restart
- SSH is allowed before enabling the firewall
- Existing sessions remain open during SSH and firewall changes
- Every functional milestone is committed separately
The environment can be rebuilt from:
- Terraform configuration
- Cloud-init templates
- Ansible inventory generation
- Ansible roles
- Collection dependency files
- Git history
- Add a managed login banner
- Create a dedicated validation playbook
- Add package and service assertions
- Add
ansible-lint - Add Ansible Vault fundamentals
- Test baseline persistence after reboot
- Expand role documentation
- Install Jenkins
- Create a Jenkins pipeline
- Run Terraform format and validation checks
- Run Terraform plan and apply stages
- Generate the Ansible inventory
- Run Ansible syntax and lint checks
- Apply the Linux baseline
- Run post-deployment validation
- Deploy Oracle Database Free
- Configure listener and services
- Create users, schemas, roles, and privileges
- Configure database auditing
- Add backup and restore exercises
- Add Python database connectivity
- Add additional database platforms
- Deploy Prometheus
- Deploy Grafana
- Add centralised logging
- Collect Linux and database audit events
- Simulate database activity monitoring policies
- Create security alerts and dashboards
- Generate a simulated server inventory
- Generate application and database records
- Create migration waves
- Implement migration pre-checks
- Implement post-migration validation
- Add reporting and rollback procedures
- Simulate service failures
- Simulate SSH configuration failures
- Test rollback procedures
- Test VM recreation
- Test backup and restore
- Document incident-response procedures
A short demonstration can use the following workflow.
Show recent Git history:
git log --oneline --decorate -10Show Terraform idempotency:
terraform -chdir=terraform/environments/lab planGenerate the Ansible inventory:
./scripts/generate-ansible-inventory.shShow the inventory:
cd ansible
ansible-inventory --graphTest connectivity:
ansible terraform_vms -m pingShow available role tags:
ansible-playbook playbooks/linux-baseline.yml --list-tagsRun the complete baseline:
ansible-playbook playbooks/linux-baseline.ymlA successful demonstration ends with:
changed=0
unreachable=0
failed=0
This proves that the Terraform-managed infrastructure and Ansible-managed operating-system configuration already match the desired state.
The virtualisation, Terraform, GitHub, and core Ansible foundations are operational.
Current working capabilities include:
Terraform VM provisioning
Cloud-init bootstrap
Terraform DHCP discovery
Generated Ansible inventory
Reusable Linux baseline
Package management
Audit service enforcement
Time synchronization
SSH hardening
UFW firewall management
Tagged Ansible execution
Check mode
Idempotency validation
GitHub change history
The next major milestone is completing Ansible validation and documentation, followed by Jenkins pipeline orchestration and database deployment.
This project is a personal technical lab built for learning and demonstration purposes.
It is not connected to, endorsed by, or representative of any employer’s real production infrastructure. It uses a small lab environment to demonstrate general enterprise engineering principles such as automation, security, repeatability, validation, and change control.