This repository contains a production-ready Ansible configuration that automates the complete setup of a fresh Ubuntu VPS server for web application hosting.
This playbook sets up a secure and ready-to-deploy environment with:
- Updates & upgrades all packages
- Installs tools:
curl,git,unzip,build-essential,ufw
- Creates a secure
appuserwith sudo privileges - Adds SSH key authentication
- Node.js 22 (via NVM)
- PM2 process manager for Node apps
- PHP + Composer + Laravel Installer
- Python 3 + pip + venv + Django
- Nginx (pre-configured with sample frontend site)
- Apache2 (sample virtual host setup)
- UFW firewall with common ports open (SSH, HTTP, HTTPS)
- Certbot for free HTTPS (Let's Encrypt)
C:.
├───group_vars
└───roles
├───apache
│ └───tasks
├───common
│ └───tasks
├───firewall
│ ├───files
│ └───tasks
├───nginx
│ └───tasks
├───node
│ └───tasks
├───php
│ └───tasks
├───pm2
│ └───tasks
├───python
│ └───tasks
└───user
└───tasks
git clone https://github.com/your-org/ansible-server-setup.git
cd ansible-server-setup Open or create the missing inventory.ini as we have the example sample format, and set your server IP and SSH user:
[web]
your.server.ip.here ansible_user=rootpython3 generate\_inventory.py
Make sure your SSH key is added to your agent and you're able to SSH into the server:
ssh root@your.server.ip.here
Run a dry-run check before applying:
ansible-playbook playbook.yml -i inventory.ini --check --diff
To apply the full server setup:
ansible-playbook playbook.yml -i inventory.ini
🧠 Tips
📌 You can add more roles as needed.
🐳 Docker role can be added separately.
🧪 Always use --check before deploying to production.
🔄 Re-run the playbook anytime to patch or update the server.
💡 Requirements
Ansible 2.14+
Python 3 (on your local machine)
SSH key-based login to your Ubuntu VPS
🛡️ Security Notice
Your IP address in inventory.ini is not sensitive.
Never commit private SSH keys or passwords.
Use .gitignore to exclude credentials or secrets.
📬 Contact
Enis Gjocaj
For questions, feel free to open an issue or email us.