|
| 1 | +# Ansible Playbooks |
| 2 | + |
| 3 | +This directory contains Ansible playbooks and roles to install K3s, deploy ArgoCD, push application secrets, and install IAM/monitoring stacks onto the K3s cluster. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Ansible 2.14+ |
| 8 | +- `kubectl` and `helm` on the machine running the playbooks |
| 9 | +- Access to the target VMs (SSH) |
| 10 | +- (Recommended) Ansible Vault for secrets |
| 11 | + |
| 12 | +## Inventory |
| 13 | + |
| 14 | +Create an inventory file (e.g., `inventory.ini`) with one `k3s_master` host and one or more `k3s_worker` hosts: |
| 15 | + |
| 16 | +```ini |
| 17 | +[k3s_master] |
| 18 | +master ansible_host=<MASTER_PUBLIC_IP> ansible_user=azureuser private_ip=<MASTER_PRIVATE_IP> |
| 19 | + |
| 20 | +[k3s_worker] |
| 21 | +worker ansible_host=<WORKER_PUBLIC_IP> ansible_user=azureuser private_ip=<WORKER_PRIVATE_IP> |
| 22 | +``` |
| 23 | + |
| 24 | +The `private_ip` host var is required by the K3s playbook to join workers and to populate the kubeconfig. |
| 25 | + |
| 26 | +## Secrets |
| 27 | + |
| 28 | +Some playbooks load `playbooks/secrets.yml`. It should include values like: |
| 29 | + |
| 30 | +- `database_url` |
| 31 | +- `nextauth_secret` |
| 32 | +- `wso2_issuer` |
| 33 | +- `wso2_well_known` |
| 34 | +- `wso2_logout_url` |
| 35 | +- `node_tls_reject_unauthorized` |
| 36 | +- `student_url`, `library_url`, `admin_url` |
| 37 | +- `student_wso2_client_id`, `student_wso2_client_secret` |
| 38 | +- `library_wso2_client_id`, `library_wso2_client_secret` |
| 39 | +- `admin_wso2_client_id`, `admin_wso2_client_secret` |
| 40 | +- `grafana_admin_password` |
| 41 | + |
| 42 | +> Tip: Store `secrets.yml` with Ansible Vault: `ansible-vault create playbooks/secrets.yml`. |
| 43 | +
|
| 44 | +## Playbooks |
| 45 | + |
| 46 | +Run playbooks from `infrastructure/ansible`: |
| 47 | + |
| 48 | +```bash |
| 49 | +cd infrastructure/ansible |
| 50 | +``` |
| 51 | + |
| 52 | +### 1) Install K3s |
| 53 | + |
| 54 | +```bash |
| 55 | +ansible-playbook playbooks/install-k3s.yml -i inventory.ini -e "public_ip=<MASTER_PUBLIC_IP>" -e "private_ip=<MASTER_PRIVATE_IP>" |
| 56 | +``` |
| 57 | + |
| 58 | +This produces `kubeconfig_azure.yaml` in the current directory and stores the cluster token for worker joins. |
| 59 | + |
| 60 | +### 2) Deploy ArgoCD |
| 61 | + |
| 62 | +```bash |
| 63 | +ansible-playbook playbooks/install-argocd.yml |
| 64 | +``` |
| 65 | + |
| 66 | +### 3) Deploy Application Secrets |
| 67 | + |
| 68 | +```bash |
| 69 | +ansible-playbook playbooks/deploy-secrets.yml |
| 70 | +``` |
| 71 | + |
| 72 | +### 4) Install IAM Stack (WSO2 + MySQL) |
| 73 | + |
| 74 | +```bash |
| 75 | +ansible-playbook playbooks/install-iam-stack.yml |
| 76 | +``` |
| 77 | + |
| 78 | +### 5) Deploy Monitoring Stack (Prometheus + Grafana) |
| 79 | + |
| 80 | +```bash |
| 81 | +ansible-playbook playbooks/monitoring-stack.yaml |
| 82 | +``` |
| 83 | + |
| 84 | +## Notes |
| 85 | + |
| 86 | +- If you rotate or change secrets, rerun the `deploy-secrets.yml` playbook. |
| 87 | +- All playbooks assume `kubeconfig_azure.yaml` exists in the working directory. |
0 commit comments