Skip to content

Commit 5be9324

Browse files
committed
fix(deployment): add argocd (#36)
1 parent a3c9a7f commit 5be9324

File tree

1 file changed

+80
-79
lines changed

1 file changed

+80
-79
lines changed

ansible/main.yaml

Lines changed: 80 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
KUBECONFIG_PATH: "/home/{{ OS_USER }}/.kube/config"
1010
HELM_URL: "https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3"
1111
SEND_NOTIFICATIONS: false
12-
ENABLE_MONITORING: false
13-
OPEN_PORT_GRAFANA: false
1412
ENABLE_EDA_STACK: true
1513
ENABLE_ARGOCD: true
1614
OPEN_PORT_ARGOCD: true
@@ -28,11 +26,12 @@
2826
- name: Install packages
2927
ansible.builtin.apt:
3028
pkg:
31-
- wget
32-
- curl
33-
- snapd
34-
- git
29+
- wget
30+
- curl
31+
- snapd
32+
- git
3533
- kubecolor
34+
- jq
3635

3736
- name: Install snapd
3837
community.general.snap:
@@ -41,7 +40,7 @@
4140

4241
- name: Install microk8s
4342
community.general.snap:
44-
name:
43+
name:
4544
- microk8s
4645
classic: true
4746

@@ -58,7 +57,7 @@
5857
ansible.builtin.shell: |
5958
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
6059
chmod +x kubectl
61-
mv ./kubectl /usr/local/bin/kubectl
60+
mv ./kubectl /usr/local/bin/kubectl
6261
args:
6362
executable: /bin/bash
6463

@@ -122,64 +121,6 @@
122121
become_user: "{{ OS_USER }}"
123122
ansible.builtin.shell: |
124123
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 &
183124
args:
184125
executable: /bin/bash
185126

@@ -226,14 +167,34 @@
226167
repo_url: https://argoproj.github.io/argo-helm
227168

228169
- name: Install ArgoCD
229-
when: ENABLE_ARGOCD
230170
become_user: "{{ OS_USER }}"
231171
kubernetes.core.helm:
232172
name: argocd
233173
chart_ref: argocd/argo-cd
234174
release_namespace: argocd
235175
create_namespace: true
236176
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
237198

238199
- name: Get ArgoCD initial-admin-secret
239200
when: ENABLE_ARGOCD
@@ -262,14 +223,14 @@
262223
ansible.builtin.shell: |
263224
kubectl apply -Rf /tmp/gitops/argocd/
264225
args:
265-
executable: /bin/bash
226+
executable: /bin/bash
266227

267228
- name: ArgoCD base apps
268229
become_user: "{{ OS_USER }}"
269230
ansible.builtin.shell: |
270231
kubectl apply -Rf /tmp/gitops/applicationsets/
271232
args:
272-
executable: /bin/bash
233+
executable: /bin/bash
273234

274235
- name: Open ports ArgoCD
275236
become_user: "{{ OS_USER }}"
@@ -279,10 +240,59 @@
279240
args:
280241
executable: /bin/bash
281242

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+
282293
# -----------------------------------------
283294
# GLOBAL AND GENERALS
284295
# -----------------------------------------
285-
286296
- name: Send Slack notificación
287297
when: SEND_NOTIFICATIONS
288298
uri:
@@ -293,12 +303,3 @@
293303
body: '{"text":"Deployment finished, infrastructure will be ready in a few minutes..."}'
294304
body_format: json
295305
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

Comments
 (0)