Skip to content

Commit ba2a33d

Browse files
authored
Merge pull request #2 from udaaraSH23/codex/update-readme-with-ansible-terraform-usage
docs: add Ansible and Terraform usage guides
2 parents 0857f9a + 8cb2a3a commit ba2a33d

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,43 @@ Common entry points:
8888

8989
- `infrastructure/k8s/` for Kubernetes manifests (apps, database, secrets, and related resources).
9090
- `infrastructure/ansible/` for Ansible playbooks that apply deployment configuration and secrets.
91+
- `infrastructure/terraform/` for Azure infrastructure provisioning (K3s VM + networking).
9192

9293
> Review and update environment-specific values (namespace, image tags, and secrets) before applying to your environment.
9394
95+
#### Provisioning with Terraform (Azure)
96+
97+
Use Terraform to provision the Azure VMs, networking, and public IPs for a small K3s cluster.
98+
99+
1. Review or override defaults in `infrastructure/terraform/variables.tf`.
100+
2. Authenticate to Azure (e.g., `az login`) and run:
101+
102+
```bash
103+
cd infrastructure/terraform
104+
terraform init
105+
terraform apply
106+
```
107+
108+
Terraform outputs the public IPs you’ll use for Ansible inventory or SSH. For more details, see `infrastructure/terraform/README.md`.
109+
110+
#### Deploying with Ansible
111+
112+
Ansible playbooks install K3s, deploy ArgoCD, seed secrets, and install IAM/monitoring stacks.
113+
114+
1. Create an inventory with `k3s_master` and `k3s_worker` hosts.
115+
2. Create `infrastructure/ansible/playbooks/secrets.yml` (recommended via Ansible Vault) with the variables referenced by the playbooks.
116+
3. Run the playbooks from the `infrastructure/ansible` directory:
117+
118+
```bash
119+
ansible-playbook playbooks/install-k3s.yml -i inventory.ini -e "public_ip=<MASTER_PUBLIC_IP>" -e "private_ip=<MASTER_PRIVATE_IP>"
120+
ansible-playbook playbooks/install-argocd.yml
121+
ansible-playbook playbooks/deploy-secrets.yml
122+
ansible-playbook playbooks/install-iam-stack.yml
123+
ansible-playbook playbooks/monitoring-stack.yaml
124+
```
125+
126+
For prerequisites and playbook details, see `infrastructure/ansible/README.md`.
127+
94128
## Functionality Overview
95129

96130
### Student Portal

infrastructure/ansible/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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.

infrastructure/terraform/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Terraform (Azure) - K3s VM Provisioning
2+
3+
This directory provisions Azure infrastructure for a small K3s cluster (one control-plane VM and one worker VM), plus networking and security group rules.
4+
5+
## What It Creates
6+
7+
- Resource group, VNet, subnet, NSG, and NSG rules.
8+
- Two Linux VMs with public IPs.
9+
- Outputs for both public IP addresses.
10+
11+
## Prerequisites
12+
13+
- Terraform 1.x
14+
- Azure CLI authenticated (`az login`)
15+
- A valid SSH public key (defaults to `~/.ssh/id_rsa.pub`)
16+
17+
## Configure Variables
18+
19+
Defaults are defined in `variables.tf`. Override them via a `terraform.tfvars` file or CLI flags.
20+
21+
Example `terraform.tfvars`:
22+
23+
```hcl
24+
location = "eastasia"
25+
vm_size = "Standard_D2as_v4"
26+
vm_size_node2 = "Standard_B4als_v2"
27+
admin_username = "azureuser"
28+
ssh_public_key_path = "~/.ssh/id_rsa.pub"
29+
```
30+
31+
## Usage
32+
33+
```bash
34+
cd infrastructure/terraform
35+
terraform init
36+
terraform plan
37+
terraform apply
38+
```
39+
40+
After apply completes, record the IPs:
41+
42+
```bash
43+
terraform output public_ip
44+
terraform output public_ip_node2
45+
```
46+
47+
Use these values in your Ansible inventory and playbook variables.
48+
49+
## Destroy
50+
51+
```bash
52+
terraform destroy
53+
```

0 commit comments

Comments
 (0)