Skip to content

Commit 66fdab2

Browse files
authored
refactor: use just instead of make (#1119)
1 parent 239c758 commit 66fdab2

File tree

4 files changed

+131
-148
lines changed

4 files changed

+131
-148
lines changed

ansible/Makefile

Lines changed: 0 additions & 70 deletions
This file was deleted.

ansible/justfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
set shell := ["bash", "-cu"]
2+
3+
venv := ".venv"
4+
INVENTORY := env("INVENTORY", "linode.yml")
5+
6+
# Show available recipes
7+
default:
8+
@just --list
9+
@echo ""
10+
@echo "UV-BASED WORKFLOW:"
11+
@echo " 1. just install # Install ansible + deps with uv"
12+
@echo " 2. direnv allow # Auto-activate venv (one-time)"
13+
@echo " 3. just test # Test connection"
14+
@echo " 4. ansible-playbook ... # Run playbooks"
15+
16+
# Install ansible and dependencies using uv
17+
install:
18+
#!/usr/bin/env bash
19+
set -eu
20+
if ! command -v uv >/dev/null 2>&1; then
21+
echo "ERROR: uv not found. Please install uv first:"
22+
echo " curl -LsSf https://astral.sh/uv/install.sh | sh"
23+
exit 1
24+
fi
25+
uv sync
26+
source {{venv}}/bin/activate && ansible-galaxy install -r requirements.yml
27+
28+
# Remove virtual environment and ansible directories
29+
[confirm("This will delete the virtual environment and .ansible directory. Continue?")]
30+
clean:
31+
rm -rf {{venv}} .ansible
32+
33+
# Test connection to random VM (set INVENTORY env var, default: linode.yml)
34+
test:
35+
#!/usr/bin/env bash
36+
set -eu
37+
echo "Counting VMs in inventory..."
38+
if ! command -v ansible >/dev/null 2>&1; then
39+
echo "ERROR: ansible not found - did you source the venv?"
40+
echo "Run: source {{venv}}/bin/activate"
41+
exit 1
42+
fi
43+
if ! command -v jq >/dev/null 2>&1; then
44+
echo "ERROR: jq not found - please install jq"
45+
exit 1
46+
fi
47+
VM_COUNT=$(ansible-inventory -i inventory/{{INVENTORY}} --list 2>/dev/null | jq -r '._meta.hostvars | keys | length')
48+
if [ $? -ne 0 ]; then
49+
echo "ERROR: Failed to parse inventory"
50+
exit 1
51+
fi
52+
echo "Found $VM_COUNT VMs in inventory"
53+
if [ "$VM_COUNT" -eq 0 ]; then
54+
echo "ERROR: No VMs found in inventory"
55+
exit 1
56+
fi
57+
RANDOM_INDEX=$(( RANDOM % VM_COUNT ))
58+
echo "Testing connection to VM at index $RANDOM_INDEX..."
59+
if ! ansible -i inventory/{{INVENTORY}} "all[$RANDOM_INDEX]" -m ping --one-line -v; then
60+
echo "ERROR: Connection test failed"
61+
exit 1
62+
fi
63+
echo "SUCCESS: Connection test passed"

terraform/Makefile

Lines changed: 0 additions & 78 deletions
This file was deleted.

terraform/justfile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Find all directories containing .terraform.lock.hcl files
2+
workspaces := `find . -name ".terraform.lock.hcl" -exec dirname {} \; | tr '\n' ' '`
3+
4+
# Show available recipes
5+
default:
6+
@just --list
7+
8+
# Format Terraform files in all workspaces
9+
format:
10+
@echo "Formatting Terraform files in all workspaces..."
11+
@for workspace in {{workspaces}}; do \
12+
echo "Formatting $workspace"; \
13+
terraform -chdir=$workspace fmt; \
14+
done
15+
@echo "Formatting complete."
16+
17+
# List all detected Terraform workspaces
18+
list-workspaces:
19+
@echo "Detected Terraform workspaces:"
20+
@for workspace in {{workspaces}}; do \
21+
echo " $workspace"; \
22+
done
23+
24+
# Validate Terraform configurations in all workspaces
25+
validate:
26+
@echo "Validating Terraform configurations in all workspaces..."
27+
@for workspace in {{workspaces}}; do \
28+
echo "Validating $workspace"; \
29+
terraform -chdir=$workspace validate; \
30+
done
31+
@echo "Validation complete."
32+
33+
# Initialize Terraform in all workspaces
34+
init:
35+
@echo "Initializing Terraform in all workspaces..."
36+
@for workspace in {{workspaces}}; do \
37+
echo "Initializing $workspace"; \
38+
terraform -chdir=$workspace init; \
39+
done
40+
@echo "Initialization complete."
41+
42+
# Initialize and upgrade Terraform in all workspaces
43+
init-upgrade:
44+
@echo "Initializing and upgrading Terraform in all workspaces..."
45+
@for workspace in {{workspaces}}; do \
46+
echo "Initializing and upgrading $workspace"; \
47+
terraform -chdir=$workspace init -upgrade; \
48+
done
49+
@echo "Initialization and upgrade complete."
50+
51+
# Run Terraform plan in all workspaces
52+
plan:
53+
@echo "Running Terraform plan in all workspaces..."
54+
@for workspace in {{workspaces}}; do \
55+
echo "Planning $workspace"; \
56+
terraform -chdir=$workspace plan; \
57+
done
58+
@echo "Planning complete."
59+
60+
# Remove Terraform cache files from all workspaces
61+
[confirm("This will delete .terraform, tfstate, and lock files. Continue?")]
62+
clean:
63+
@echo "Cleaning Terraform cache files from all workspaces..."
64+
@for workspace in {{workspaces}}; do \
65+
echo "Cleaning $workspace"; \
66+
rm -rf $workspace/.terraform $workspace/*.tfstate* $workspace/.terraform.lock.hcl; \
67+
done
68+
@echo "Cleaning complete."

0 commit comments

Comments
 (0)