|
9 | 9 | KUBECONFIG_PATH: "/home/{{ OS_USER }}/.kube/config" |
10 | 10 | HELM_URL: "https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3" |
11 | 11 | SEND_NOTIFICATIONS: false |
12 | | - ENABLE_MONITORING: false |
13 | | - OPEN_PORT_GRAFANA: false |
14 | 12 | ENABLE_EDA_STACK: true |
15 | 13 | ENABLE_ARGOCD: true |
16 | 14 | OPEN_PORT_ARGOCD: true |
|
28 | 26 | - name: Install packages |
29 | 27 | ansible.builtin.apt: |
30 | 28 | pkg: |
31 | | - - wget |
32 | | - - curl |
33 | | - - snapd |
34 | | - - git |
| 29 | + - wget |
| 30 | + - curl |
| 31 | + - snapd |
| 32 | + - git |
35 | 33 | - kubecolor |
| 34 | + - jq |
36 | 35 |
|
37 | 36 | - name: Install snapd |
38 | 37 | community.general.snap: |
|
41 | 40 |
|
42 | 41 | - name: Install microk8s |
43 | 42 | community.general.snap: |
44 | | - name: |
| 43 | + name: |
45 | 44 | - microk8s |
46 | 45 | classic: true |
47 | 46 |
|
|
58 | 57 | ansible.builtin.shell: | |
59 | 58 | curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" |
60 | 59 | chmod +x kubectl |
61 | | - mv ./kubectl /usr/local/bin/kubectl |
| 60 | + mv ./kubectl /usr/local/bin/kubectl |
62 | 61 | args: |
63 | 62 | executable: /bin/bash |
64 | 63 |
|
|
122 | 121 | become_user: "{{ OS_USER }}" |
123 | 122 | ansible.builtin.shell: | |
124 | 123 | echo 'alias kubectl="kubecolor"' >> /home/{{ OS_USER }}/.bashrc |
125 | | - args: |
126 | | - executable: /bin/bash |
127 | | - |
128 | | -# ----------------------------------------- |
129 | | -# MONITORING STACK |
130 | | -# ----------------------------------------- |
131 | | - |
132 | | - - name: Add helm repo prometheus |
133 | | - when: ENABLE_MONITORING |
134 | | - become_user: "{{ OS_USER }}" |
135 | | - kubernetes.core.helm_repository: |
136 | | - name: prometheus-community |
137 | | - repo_url: https://prometheus-community.github.io/helm-charts |
138 | | - |
139 | | - - name: Install Prometheus. |
140 | | - when: ENABLE_MONITORING |
141 | | - become_user: "{{ OS_USER }}" |
142 | | - kubernetes.core.helm: |
143 | | - name: prometheus |
144 | | - chart_ref: prometheus-community/prometheus |
145 | | - release_namespace: monitoring |
146 | | - create_namespace: true |
147 | | - wait: true |
148 | | - |
149 | | - - name: Add helm repo grafana |
150 | | - when: ENABLE_MONITORING |
151 | | - become_user: "{{ OS_USER }}" |
152 | | - kubernetes.core.helm_repository: |
153 | | - name: grafana |
154 | | - repo_url: https://grafana.github.io/helm-charts |
155 | | - |
156 | | - - name: Install Loki |
157 | | - when: ENABLE_MONITORING |
158 | | - become_user: "{{ OS_USER }}" |
159 | | - kubernetes.core.helm: |
160 | | - name: loki |
161 | | - chart_ref: grafana/loki-stack |
162 | | - release_namespace: monitoring |
163 | | - create_namespace: true |
164 | | - wait: true |
165 | | - |
166 | | - - name: Install Grafana |
167 | | - when: ENABLE_MONITORING |
168 | | - become_user: "{{ OS_USER }}" |
169 | | - kubernetes.core.helm: |
170 | | - name: grafana |
171 | | - chart_ref: grafana/grafana |
172 | | - release_namespace: monitoring |
173 | | - create_namespace: true |
174 | | - wait: true |
175 | | - values_files: |
176 | | - - https://raw.githubusercontent.com/jpradoar/event-driven-architecture/refs/heads/main/monitoring/grafana-values.yaml |
177 | | - |
178 | | - - name: Open grafana port |
179 | | - when: OPEN_PORT_GRAFANA |
180 | | - become_user: "{{ OS_USER }}" |
181 | | - ansible.builtin.shell: | |
182 | | - nohup kubectl -n monitoring port-forward --address 0.0.0.0 service/grafana 3000:80 > /tmp/kubectl_grafana.log 2>&1 & |
183 | 124 | args: |
184 | 125 | executable: /bin/bash |
185 | 126 |
|
|
226 | 167 | repo_url: https://argoproj.github.io/argo-helm |
227 | 168 |
|
228 | 169 | - name: Install ArgoCD |
229 | | - when: ENABLE_ARGOCD |
230 | 170 | become_user: "{{ OS_USER }}" |
231 | 171 | kubernetes.core.helm: |
232 | 172 | name: argocd |
233 | 173 | chart_ref: argocd/argo-cd |
234 | 174 | release_namespace: argocd |
235 | 175 | create_namespace: true |
236 | 176 | wait: true |
| 177 | + values: |
| 178 | + configs: |
| 179 | + cm: |
| 180 | + statusbadge.enabled: "true" # habilitar el statusbadge para poder ver las apps deployadas sin loguear a argocd |
| 181 | + accounts.showappsapi: apiKey,login |
| 182 | + rbac: |
| 183 | + policy.csv: | |
| 184 | + # Rol de solo lectura sobre todas las aplicaciones |
| 185 | + p, role:readonly, applications, get, */*, allow |
| 186 | + p, role:readonly, applications, list, *, allow |
| 187 | + # Asigna el usuario showappsapi al rol readonly |
| 188 | + g, showappsapi, role:readonly |
| 189 | + scopes: "[groups]" |
| 190 | + |
| 191 | + - name: Install ArgoCD CLI |
| 192 | + ansible.builtin.shell: | |
| 193 | + curl -sSL -o /tmp/argocd-v3.1.0 https://github.com/argoproj/argo-cd/releases/download/v3.1.0/argocd-linux-amd64 |
| 194 | + chmod +x /tmp/argocd-v3.1.0 |
| 195 | + mv /tmp/argocd-v3.1.0 /usr/local/bin/argocd |
| 196 | + args: |
| 197 | + executable: /bin/bash |
237 | 198 |
|
238 | 199 | - name: Get ArgoCD initial-admin-secret |
239 | 200 | when: ENABLE_ARGOCD |
|
262 | 223 | ansible.builtin.shell: | |
263 | 224 | kubectl apply -Rf /tmp/gitops/argocd/ |
264 | 225 | args: |
265 | | - executable: /bin/bash |
| 226 | + executable: /bin/bash |
266 | 227 |
|
267 | 228 | - name: ArgoCD base apps |
268 | 229 | become_user: "{{ OS_USER }}" |
269 | 230 | ansible.builtin.shell: | |
270 | 231 | kubectl apply -Rf /tmp/gitops/applicationsets/ |
271 | 232 | args: |
272 | | - executable: /bin/bash |
| 233 | + executable: /bin/bash |
273 | 234 |
|
274 | 235 | - name: Open ports ArgoCD |
275 | 236 | become_user: "{{ OS_USER }}" |
|
279 | 240 | args: |
280 | 241 | executable: /bin/bash |
281 | 242 |
|
| 243 | + - name: Show process |
| 244 | + become_user: "{{ OS_USER }}" |
| 245 | + register: show_process |
| 246 | + ansible.builtin.shell: | |
| 247 | + ps aux |grep -i forwa |grep -v grep |
| 248 | + args: |
| 249 | + executable: /bin/bash |
| 250 | + - debug: |
| 251 | + msg: "{{ show_process.stdout }}" |
| 252 | + |
| 253 | + - name: Install ArgoCD CLI |
| 254 | + become_user: "{{ OS_USER }}" |
| 255 | + ansible.builtin.shell: | |
| 256 | + argocd login {{ ansible_ssh_host }}:8081 --username admin --password {{ argocd_initial_admin_secret.stdout }} --insecure |
| 257 | + args: |
| 258 | + executable: /bin/bash |
| 259 | + |
| 260 | + - name: Install ArgoCD CLI |
| 261 | + become_user: "{{ OS_USER }}" |
| 262 | + ansible.builtin.shell: | |
| 263 | + argocd account generate-token --account showappsapi |
| 264 | + args: |
| 265 | + executable: /bin/bash |
| 266 | + register: argocd_user_token |
| 267 | + |
| 268 | + - name: Curl Test |
| 269 | + become_user: "{{ OS_USER }}" |
| 270 | + ansible.builtin.shell: | |
| 271 | + curl -s -k -H "Authorization: Bearer {{ argocd_user_token.stdout }}" \ |
| 272 | + "https://{{ ansible_ssh_host }}:8081/api/v1/applications" | jq -r . |
| 273 | + args: |
| 274 | + executable: /bin/bash |
| 275 | + register: test_curl |
| 276 | + |
| 277 | + - name: Show ArgoCD secret |
| 278 | + debug: |
| 279 | + msg: "Responde: {{ test_curl.stdout }}" |
| 280 | + |
| 281 | + - name: Create kubernetes secret from argo-token |
| 282 | + become_user: "{{ OS_USER }}" |
| 283 | + ansible.builtin.shell: | |
| 284 | + kubectl -n argocd create secret generic showappsapi-secret --from-literal=showappsapi-secret={{ argocd_user_token.stdout }} |
| 285 | + args: |
| 286 | + executable: /bin/bash |
| 287 | + |
| 288 | + - name: Show github api token |
| 289 | + debug: |
| 290 | + msg: "{{ argocd_user_token.stdout }}" |
| 291 | + |
| 292 | + |
282 | 293 | # ----------------------------------------- |
283 | 294 | # GLOBAL AND GENERALS |
284 | 295 | # ----------------------------------------- |
285 | | - |
286 | 296 | - name: Send Slack notificación |
287 | 297 | when: SEND_NOTIFICATIONS |
288 | 298 | uri: |
|
293 | 303 | body: '{"text":"Deployment finished, infrastructure will be ready in a few minutes..."}' |
294 | 304 | body_format: json |
295 | 305 | ignore_errors: yes |
296 | | - |
297 | | - - name: Show process |
298 | | - register: show_process |
299 | | - ansible.builtin.shell: | |
300 | | - ps aux |grep -i forwa |grep -v grep |
301 | | - args: |
302 | | - executable: /bin/bash |
303 | | - - debug: |
304 | | - msg: "{{ show_process.stdout }}" |
|
0 commit comments