-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseSetup.yml
More file actions
166 lines (146 loc) · 4.82 KB
/
Copy pathbaseSetup.yml
File metadata and controls
166 lines (146 loc) · 4.82 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
---
- name: Home Server Base Setup
hosts: home_servers
gather_facts: no
become: yes
tasks:
- name: Install Python (For VM)
raw: apt update && apt install -y python3
changed_when: false
- name: Update System
apt:
name: "*"
state: latest
update_cache: yes
- name: Set Timezone (Change as Needed)
timezone:
name: Asia/Jakarta
- name: Install Basic Tools
apt:
name:
- htop
- curl
- wget
- git
- vim
- net-tools
- unzip
- software-properties-common
- apt-transport-https
- ca-certificates
- gnupg
- lsb-release
state: present
update_cache: yes
- name: Install SSH (If Not Installed)
apt:
name: openssh-server
state: present
update_cache: yes
- name: Allow SSH + Active Firewall
ufw:
rule: allow
name: OpenSSH
state: enabled
- name: Install CasaOS + Docker
shell: curl -fsSL https://get.casaos.io | bash
args:
creates: /usr/bin/casaos
- name: Check if Tailscale is installed via Docker
shell: docker ps -a -q -f name=tailscale
register: tailscale_status
changed_when: false
- name: Install Tailscale via Docker (If Not Installed)
shell: |
docker run -d --name tailscale \
--restart=unless-stopped \
--network=host \
--cap-add=NET_ADMIN \
--cap-add=NET_RAW \
-v tailscale:/var/lib/tailscale \
-v /dev/net/tun:/dev/net/tun \
-e TS_AUTHKEY="{{ ts_key }}" \
tailscale/tailscale:latest
when: tailscale_status.stdout == ""
- name: Check if Cloudflare Tunnel is installed via Docker
shell: docker ps -a -q -f name=cloudflare
register: cloudflare_status
changed_when: false
- name: Install Cloudflare Tunnel
shell: |
docker run -d --name cloudflare \
--restart=unless-stopped \
--network=host \
-e TUNNEL_TOKEN="{{ cf_token }}" \
cloudflare/cloudflared:latest tunnel --no-autoupdate run
when: cloudflare_status.stdout == ""
- name: Check if Monitoring is installed via Docker
shell: docker ps -a -q -f name=prometheus
register: monitoring_status
changed_when: false
- name: Install Monitoring Tools (Prometheus + Grafana)
block:
- name: Create Monitoring Directory
file:
path: /opt/monitoring
state: directory
mode: '0755'
- name: Create Monitoring Docker-Compose file
copy:
dest: /opt/monitoring/docker-compose.yml
content: |
services:
node_exporter:
image: quay.io/prometheus/node-exporter:latest
container_name: node_exporter
command:
- '--path.rootfs=/host'
network_mode: host
pid: host
restart: unless-stopped
volumes:
- '/:/host:ro,rslave'
prometheus:
image: prom/prometheus:latest
container_name: prometheus
restart: unless-stopped
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
grafana:
image: grafana/grafana:latest
container_name: grafana
restart: unless-stopped
ports:
- "3101:3000"
environment:
- GF_SECURITY_ADMIN_USER={{ grafana_user }}
- GF_SECURITY_ADMIN_PASSWORD={{ grafana_pass }}
volumes:
- grafana_data:/var/lib/grafana
volumes:
prometheus_data:
grafana_data:
- name: Create Prometheus Config File (Change target IP as needed)
copy:
dest: /opt/monitoring/prometheus.yml
content: |
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100']
- name: Start Monitoring Docker
shell: docker compose up -d
args:
chdir: /opt/monitoring
when: monitoring_status.stdout == ""