137 lines
2.4 KiB
Markdown
137 lines
2.4 KiB
Markdown
# 🚀 Ansible Web Server Automation
|
|
|
|
Simple, production-ready Ansible project for automated web server setup.
|
|
|
|
## 📋 Features
|
|
|
|
- ✅ Nginx web server installation
|
|
- ✅ Firewall configuration (UFW)
|
|
- ✅ Application deployment
|
|
- ✅ User management
|
|
- ✅ SSL/TLS support
|
|
- ✅ Automated configuration
|
|
|
|
## 🏗️ Structure
|
|
|
|
```
|
|
ansible/webserver-automation/
|
|
├── ansible.cfg # Ansible config
|
|
├── inventory/ # Server inventory
|
|
│ ├── production
|
|
│ └── development
|
|
├── group_vars/ # Variables
|
|
│ ├── all.yml
|
|
│ └── webservers.yml
|
|
├── playbooks/ # Playbooks
|
|
│ ├── site.yml # Main playbook
|
|
│ └── deploy.yml # Deployment
|
|
└── roles/ # Ansible roles
|
|
├── common/
|
|
├── nginx/
|
|
└── firewall/
|
|
```
|
|
|
|
## 🚀 Quick Start
|
|
|
|
### Install Ansible
|
|
```bash
|
|
sudo apt install ansible -y
|
|
```
|
|
|
|
### Clone Project
|
|
```bash
|
|
git clone http://git.thedevops.dev/admin/k3s-gitops.git
|
|
cd k3s-gitops/ansible/webserver-automation
|
|
```
|
|
|
|
### Configure
|
|
Edit `inventory/production`:
|
|
```ini
|
|
[webservers]
|
|
web1 ansible_host=192.168.1.10
|
|
|
|
[all:vars]
|
|
ansible_user=ubuntu
|
|
```
|
|
|
|
### Run
|
|
```bash
|
|
# Test connection
|
|
ansible -i inventory/production all -m ping
|
|
|
|
# Deploy
|
|
ansible-playbook -i inventory/production playbooks/site.yml
|
|
```
|
|
|
|
## 📚 Usage
|
|
|
|
### Full Setup
|
|
```bash
|
|
ansible-playbook -i inventory/production playbooks/site.yml
|
|
```
|
|
|
|
### Deploy App
|
|
```bash
|
|
ansible-playbook -i inventory/production playbooks/deploy.yml
|
|
```
|
|
|
|
### Check Mode (Dry Run)
|
|
```bash
|
|
ansible-playbook -i inventory/production playbooks/site.yml --check
|
|
```
|
|
|
|
### Verbose
|
|
```bash
|
|
ansible-playbook -i inventory/production playbooks/site.yml -vv
|
|
```
|
|
|
|
## 🔧 Configuration
|
|
|
|
Edit `group_vars/webservers.yml`:
|
|
```yaml
|
|
nginx_port: 80
|
|
app_name: myapp
|
|
app_dir: /var/www/myapp
|
|
domain_name: example.com
|
|
```
|
|
|
|
## 🔐 Security
|
|
|
|
### SSH Keys
|
|
```bash
|
|
ssh-keygen -t ed25519
|
|
ssh-copy-id ubuntu@192.168.1.10
|
|
```
|
|
|
|
### Ansible Vault
|
|
```bash
|
|
ansible-vault encrypt group_vars/production.yml
|
|
ansible-vault edit group_vars/production.yml
|
|
```
|
|
|
|
## 🧪 Testing
|
|
|
|
```bash
|
|
# Syntax check
|
|
ansible-playbook playbooks/site.yml --syntax-check
|
|
|
|
# List tasks
|
|
ansible-playbook -i inventory/production playbooks/site.yml --list-tasks
|
|
```
|
|
|
|
## 📦 Requirements
|
|
|
|
- Ansible >= 2.9
|
|
- Python >= 3.6
|
|
- Target: Ubuntu 20.04/22.04
|
|
- SSH access
|
|
|
|
## 📄 License
|
|
|
|
MIT
|
|
|
|
---
|
|
|
|
**Status:** ✅ Ready to use!
|
|
**Version:** 1.0.0
|