openclaw/
├── terraform/ # Infrastructure provisioning
│ ├── main.tf # Main Terraform config
│ ├── variables.tf # Variable definitions
│ ├── outputs.tf # Output definitions
│ └── terraform.tfvars # Your values (not committed)
│
├── ansible/ # Configuration management
│ ├── ansible.cfg # Ansible configuration
│ ├── inventory/ # Inventory files
│ │ ├── hosts # Host definitions
│ │ └── group_vars/ # Group variables
│ ├── playbooks/ # Playbooks
│ │ ├── site.yml # Main playbook
│ │ └── *.yml # Additional playbooks
│ └── roles/ # Ansible roles
│ ├── common/ # Common system setup
│ ├── docker/ # Docker installation
│ └── openclaw/ # Application deployment
│
├── scripts/ # Helper scripts
│ ├── setup.sh # Initial setup
│ ├── deploy.sh # Deployment script
│ └── manage.sh # Management script
│
└── docs/ # Documentation
├── PROXMOX_SETUP.md # Proxmox preparation
├── DEPLOYMENT.md # Deployment guide
└── REQUIREMENTS.md # Requirements list
Modify terraform/variables.tf to add new VM options:
variable "new_option" {
description = "Description"
type = string
default = "value"
}Update terraform/main.tf to use the variable.
Add new roles in ansible/roles/:
mkdir -p ansible/roles/myrole/{tasks,handlers,templates,files}Create ansible/roles/myrole/tasks/main.yml:
---
- name: My task
apt:
name: mypackage
state: presentAdd role to ansible/playbooks/site.yml:
roles:
- common
- docker
- myrole
- openclawModify ansible/roles/openclaw/templates/docker-compose.yml.j2 to add services:
services:
newservice:
image: myimage:latest
ports:
- "3000:3000"
environment:
KEY: valueAdd variables to ansible/inventory/group_vars/all.yml:
my_new_var: "value"Use in templates:
{{ my_new_var }}
postgres:
image: postgres:15
environment:
POSTGRES_USER: openclaw
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: openclaw
volumes:
- postgres-data:/var/lib/postgresql/data- Add variables to ansible/inventory/group_vars/all.yml:
openclaw_env_vars:
DATABASE_URL: "postgresql://openclaw:password@postgres:5432/openclaw"- Update firewall rules if needed:
ufw_allow_ports:
- "5432"Create a new role ansible/roles/monitoring/:
# tasks/main.yml
- name: Install Prometheus
# ... tasks
- name: Install Grafana
# ... tasks- Create role
ansible/roles/nginx/ - Add Let's Encrypt with certbot
- Configure reverse proxy
Example structure:
# roles/nginx/tasks/main.yml
- name: Install nginx
apt:
name: nginx
state: present
- name: Configure nginx
template:
src: nginx.conf.j2
dest: /etc/nginx/sites-available/openclaw
notify: reload nginxcd terraform
terraform fmt # Format code
terraform validate # Validate syntax
terraform plan # Preview changescd ansible
# Check syntax
ansible-playbook --syntax-check playbooks/site.yml
# Dry run
ansible-playbook -i inventory/hosts playbooks/site.yml --check
# Run specific role
ansible-playbook -i inventory/hosts playbooks/site.yml --tags docker
# Verbose output
ansible-playbook -vvv -i inventory/hosts playbooks/site.ymlCreate a test inventory:
cp -r ansible/inventory ansible/inventory-dev
# Edit ansible/inventory-dev/hosts with test VM IPRun against dev:
ansible-playbook -i ansible/inventory-dev/hosts playbooks/site.yml- Use consistent naming (lowercase, underscores)
- Add descriptions to all variables
- Use meaningful variable names
- Comment complex logic
- Use YAML syntax consistently (2 spaces)
- Name all tasks descriptively
- Use tags for role organization
- Keep playbooks simple, move logic to roles
- Use handlers for service restarts
- Use shellcheck for validation
- Add error handling (
set -e) - Use meaningful variable names
- Add usage/help functions
- Use colors for output clarity
- Test your changes thoroughly
- Update documentation
- Follow existing code style
- Add comments for complex logic
- Create clear commit messages
Edit ansible/inventory/group_vars/all.yml:
ufw_allow_ports:
- "22"
- "80"
- "443"
- "8080"
- "9090" # New portEdit ansible/inventory/group_vars/all.yml:
openclaw_port: 3000 # Changed from 8080Re-run deployment:
./scripts/deploy.sh --ansible-onlyCreate ansible/roles/openclaw/files/backup-cron.sh:
#!/bin/bash
tar -czf /backups/openclaw-$(date +%Y%m%d).tar.gz /var/lib/openclawAdd task in role:
- name: Setup backup cron job
cron:
name: "Daily OpenClaw backup"
hour: "2"
minute: "0"
job: "/opt/openclaw/backup-cron.sh"- Terraform Documentation
- Ansible Documentation
- Proxmox API Documentation
- Docker Compose Documentation
- Check existing documentation in
docs/ - Review similar implementations in roles/
- Test in development environment first
- Ask for clarification before major changes