Commit f9bd767c authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

remove readme since we have docs

parent 7788072a
Loading
Loading
Loading
Loading

ansible/README.md

deleted100644 → 0
+0 −375
Original line number Diff line number Diff line
# Ansible Automation for Operator Platform

This directory contains Ansible playbooks and roles for automating the deployment and management of the Operator Platform with i2edge on Kind (Kubernetes in Docker).

## 📋 Prerequisites

### System Requirements
- **OS**: Linux (tested on Ubuntu/Debian)
- **Ansible**: >= 2.15
- **Python**: >= 3.8
- **Docker**: Installed and running
- **kubectl**: Installed (for cluster verification)

### Install Ansible

Install Python virtual environment

```bash
sudo apt install python3-virtualenv
```



```bash
source venv/bin/activate  # Activate your Python virtual environment
pip install ansible
```

### Install Required Collections
```bash
cd ansible
ansible-galaxy collection install -r requirements.yml
```

This installs:
- `kubernetes.core` - Kubernetes resource management
- `community.docker` - Docker operations
- `community.general` - General utilities

### Install Python Dependencies
```bash
pip3 install kubernetes docker
```

## 🏗️ Directory Structure

```
ansible/
├── ansible.cfg                 # Ansible configuration
├── requirements.yml            # Required Ansible collections
├── inventory/
│   └── hosts.yml              # Inventory for localhost
├── group_vars/
│   └── all.yml                # Global variables
├── playbooks/
│   ├── 01-deploy-kind-cluster.yml        # Create Kind cluster
│   ├── 02-install-dependencies.yml       # Install Prometheus, NFD (TODO)
│   ├── 03-deploy-i2edge.yml              # Deploy i2edge (TODO)
│   └── 99-undeploy-kind-cluster.yml      # Delete cluster
└── roles/
    └── kind-cluster/          # Kind cluster management role
```

## 🚀 Quick Start

### 1. Deploy Kind Cluster

```bash
cd ansible
ansible-playbook playbooks/01-deploy-kind-cluster.yml
```

This will:
- Install Kind CLI (if not present)
- Create a Kind cluster named `operator-platform`
- Generate and configure kubeconfig
- Verify cluster is accessible
- Display access information

**Options:**
```bash
# Force recreate if cluster exists
ansible-playbook playbooks/01-deploy-kind-cluster.yml -e "recreate_cluster=yes"

# Use custom cluster name
ansible-playbook playbooks/01-deploy-kind-cluster.yml -e "kind_cluster_name=my-cluster"

# Dry run (check mode)
ansible-playbook playbooks/01-deploy-kind-cluster.yml --check
```

### 2. Configure Your Environment

After deployment, set up your environment:

```bash
# Option 1: Source the setup script
source ../automation/1-kind-cluster/setup-env.sh

# Option 2: Manually export
export KUBECONFIG=/home/sergio/i2cat/OperatorPlatform/OP_Automation/automation/1-kind-cluster/operator-platform-external-kubeconfig.yaml

# Verify
kubectl get nodes
kubectl cluster-info
```

### 3. Undeploy Cluster

```bash
ansible-playbook playbooks/99-undeploy-kind-cluster.yml
```

This will:
- Prompt for confirmation
- Delete the Kind cluster
- Remove all containers
- Clean up kubeconfig file

## ⚙️ Configuration

### Global Variables (`group_vars/all.yml`)

Key variables you can customize:

```yaml
# Cluster settings
kind_cluster_name: operator-platform
kind_version: v0.29.0
worker_nodes: 2

# Network settings
kubeconfig_server_url: "https://localhost:6443"

# Port mappings
port_mappings:
  - name: kubernetes-api
    container_port: 6443
    host_port: 6443
  - name: prometheus
    container_port: 30090
    host_port: 30090
  - name: i2edge-service
    container_port: 30769
    host_port: 30769

# Certificate SANs (add your host IP here)
cert_sans:
  - "localhost"
  - "127.0.0.1"
  # - "192.168.1.100"  # Add your IP
```

### Override Variables

You can override variables at runtime:

```bash
# Change cluster name
ansible-playbook playbooks/01-deploy-kind-cluster.yml \
  -e "kind_cluster_name=test-cluster"

# Change number of workers
ansible-playbook playbooks/01-deploy-kind-cluster.yml \
  -e "worker_nodes=3"

# Change Kind version
ansible-playbook playbooks/01-deploy-kind-cluster.yml \
  -e "kind_version=v0.20.0"
```

## 📚 Playbook Reference

### 01-deploy-kind-cluster.yml

**Purpose**: Create and configure Kind cluster

**Variables**:
- `kind_cluster_name` - Cluster name (default: `operator-platform`)
- `kind_version` - Kind binary version (default: `v0.29.0`)
- `worker_nodes` - Number of worker nodes (default: `2`)
- `recreate_cluster` - Force recreate if exists (default: `no`)

**Output**:
- Kubeconfig: `../automation/1-kind-cluster/operator-platform-external-kubeconfig.yaml`
- Config: `../automation/1-kind-cluster/kind-config.yaml`
- Setup script: `../automation/1-kind-cluster/setup-env.sh`

### 99-undeploy-kind-cluster.yml

**Purpose**: Delete Kind cluster and cleanup

**Variables**:
- `kind_cluster_name` - Cluster to delete (default: `operator-platform`)

**Safety**:
- Prompts for confirmation before deletion
- Use `-e "confirm_deletion=yes"` to skip prompt (dangerous!)

## 🔧 Advanced Usage

### Verbose Output

```bash
# Show detailed task execution
ansible-playbook playbooks/01-deploy-kind-cluster.yml -v

# Show even more detail (connection info)
ansible-playbook playbooks/01-deploy-kind-cluster.yml -vv

# Show maximum verbosity (debug)
ansible-playbook playbooks/01-deploy-kind-cluster.yml -vvv
```

### Check Mode (Dry Run)

```bash
# See what would be changed without making changes
ansible-playbook playbooks/01-deploy-kind-cluster.yml --check

# With diff output
ansible-playbook playbooks/01-deploy-kind-cluster.yml --check --diff
```

### Tags (for future playbooks)

```bash
# Run only specific parts
ansible-playbook playbooks/02-install-dependencies.yml --tags "prometheus"
ansible-playbook playbooks/02-install-dependencies.yml --skip-tags "nfd"
```

### Limit to Specific Hosts

```bash
# Run only on localhost (default)
ansible-playbook playbooks/01-deploy-kind-cluster.yml --limit localhost
```

## 🐛 Troubleshooting

### Docker Not Running

```bash
Error: Cannot connect to Docker daemon
```

**Solution**:
```bash
sudo systemctl start docker
sudo usermod -aG docker $USER  # Add user to docker group
newgrp docker  # Refresh groups
```

### Kind Not Found

```bash
Error: kind command not found
```

**Solution**: The playbook will install Kind automatically, but if you want to install manually:
```bash
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.29.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
```

### Cluster Already Exists

The playbook will prompt you to recreate. You can also:
```bash
# Force recreation
ansible-playbook playbooks/01-deploy-kind-cluster.yml -e "recreate_cluster=yes"

# Or manually delete first
kind delete cluster --name operator-platform
```

### Port Already in Use

```bash
Error: port 6443 already in use
```

**Solution**: Check what's using the port and stop it:
```bash
sudo lsof -i :6443
sudo netstat -tlnp | grep 6443

# Or use different ports in group_vars/all.yml
```

### Kubeconfig Issues

```bash
Error: The connection to the server localhost:6443 was refused
```

**Solution**:
```bash
# Ensure KUBECONFIG is set
export KUBECONFIG=/path/to/operator-platform-external-kubeconfig.yaml

# Verify cluster is running
docker ps | grep operator-platform

# Recreate cluster if needed
kind delete cluster --name operator-platform
ansible-playbook playbooks/01-deploy-kind-cluster.yml
```

## 🔄 Comparison with Shell Scripts

| Feature | Shell Script | Ansible |
|---------|-------------|---------|
| Idempotency | Manual checks | Built-in |
| Error handling | Custom | Standardized |
| Variables | Environment/hardcoded | Centralized YAML |
| Multi-target | Complex | Simple inventory |
| Reusability | Copy/paste | Roles |
| Testing | Manual | Check mode |
| Documentation | Comments | Self-documenting |
| Reporting | Echo statements | Structured output |

## 📝 Next Steps

### Future Playbooks to Create

1. **02-install-dependencies.yml**
   - Install Helm3
   - Deploy Prometheus stack
   - Install Node Feature Discovery
   - Apply node labels

2. **03-deploy-i2edge.yml**
   - Build i2edge Docker image
   - Load image into Kind
   - Create storage directories
   - Deploy via Kustomize
   - Wait for pods
   - Health checks

3. **04-undeploy-i2edge.yml**
   - Remove i2edge resources
   - Clean up PVs/PVCs
   - Verify cleanup

## 🤝 Contributing

When adding new playbooks or roles:

1. Follow the existing structure
2. Use descriptive task names
3. Add comments for complex logic
4. Test with `--check` mode first
5. Update this README
6. Use variables instead of hardcoded values

## 📄 License

Same as the parent project.

## 🆘 Support

For issues or questions:
1. Check the troubleshooting section
2. Review Ansible verbose output (`-vvv`)
3. Check the original shell scripts in `../automation/`
4. Consult Ansible documentation: https://docs.ansible.com/

---

**Created**: 18 November 2025  
**Status**: Phase 1 Complete (Kind cluster deployment)  
**Next**: Phase 2 (Dependencies installation)