-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjustfile
More file actions
117 lines (102 loc) · 4.1 KB
/
justfile
File metadata and controls
117 lines (102 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import 'src/scripts/colours.just'
# ------------------------------------------------------
# Default Command
# ------------------------------------------------------
default:
@just help
# ------------------------------------------------------
# Help Command
# ------------------------------------------------------
help:
@just _echo-white "OVH Cloud Ansible CLI"
@echo
@just _echo-white "Usage:"
@echo " just [COMMAND]"
@echo
@just _echo-yellow "Environment Setup Commands:"
@echo
@just _echo-magenta " setup"
@just _echo-white " Checks Docker, config, SSH keys directory (generates new key if empty),"
@just _echo-white " and prompts for inventory details."
@echo
@just _echo-yellow "Playbook Commands:"
@echo
@just _echo-magenta " ping"
@just _echo-white " Runs 'ansible all -m ping' to test connectivity to all inventory hosts."
@echo
@just _echo-magenta " bootstrap"
@just _echo-white " Applies the bootstrap.yml playbook (initial server hardening)."
@echo
# ------------------------------------------------------
# Setup
# ------------------------------------------------------
setup:
@just check-docker
@echo
@just check-empty-inventory
@echo
@just setup-common
@echo
@just _echo-cyan "🔑 Ensuring keys exits and git is configure ..."
@bash src/scripts/add-known-host.sh
@echo
@just _echo-info "Setup completed successfully..."
@just _echo-success "Try running 'just ping' to test access to the server."
# ------------------------------------------------------
# Check Docker
# ------------------------------------------------------
check-docker:
@just _echo-cyan "🐋 Ensuring docker is installed and avaialble ..."
@if command -v docker >/dev/null 2>&1; then \
echo "✅ Docker is already installed; skipping installation" ; \
else \
just _echo-error "❌ Docker is not installed. Please install Docker Desktop:"; \
just _echo-error " https://www.docker.com/products/docker-desktop/"; \
exit 1; \
fi
# ------------------------------------------------------
# Prompt Inventory
# ------------------------------------------------------
prompt-inventory:
@just _echo-cyan "📄 Prompting for inventory (hosts.yml)..."
@bash src/scripts/inventory.sh
check-empty-inventory:
@just _echo-cyan "📄 Ensuring ansible inventory file exists ..."
@if [ ! -f src/ansible/inventory/hosts.yml ]; then \
just _echo-warning "No inventory file found at src/ansible/inventory/hosts.yml. Creating a new one..."; \
just prompt-inventory; \
else \
echo "✅ Inventory file already exists; skipping creation." ; \
fi
# ------------------------------------------------------
# Check if Keys Directory is Empty
# ------------------------------------------------------
check-empty-keys:
@if find src/ansible/keys -maxdepth 1 -type f -name '*.pub' -print -quit | grep -q .; then \
just _echo-info "🔑 SSH public key(s) already exist in src/ansible/keys."; \
else \
just _echo-warning "No SSH public keys (*.pub) found in src/ansible/keys."; \
bash src/scripts/select-or-generate-key.sh; \
fi
# ------------------------------------------------------
# Setup Common
# ------------------------------------------------------
setup-common:
@just _echo-cyan "📦 Ensuring ansible image cytopia/ansible:2.13 ..."
@if ! docker image inspect cytopia/ansible:2.13 > /dev/null 2>&1; then \
docker pull cytopia/ansible:2.13 ; \
else \
echo "✅ Image already present — skipping pull." ; \
fi
# ------------------------------------------------------
# Ansible: Running Playbooks
# ------------------------------------------------------
run-playbook playbook:
@just _echo-cyan "🛠 Running playbook {{playbook}}..."
@docker-compose -f src/docker/docker-compose.yaml run --rm ansible \
ansible-playbook "{{playbook}}"
ping:
@docker-compose -f src/docker/docker-compose.yaml run --rm ansible \
ansible all -m ping
bootstrap:
@just run-playbook playbooks/bootstrap.yml