Skip to content

Commit a0ae6fb

Browse files
alanbchristiea.b.christie
andauthored
Auto password (#3)
* refactor: Role is now ess (was app) * feat: Playbook now gets password from deployed secret --------- Co-authored-by: a.b.christie <alan.christie@matildapeak.com>
1 parent 03e5e9f commit a0ae6fb

17 files changed

Lines changed: 55 additions & 38 deletions

.yamllint

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ yaml-files:
77

88
ignore: |
99
.github/
10-
roles/app/templates/pvc-log.yaml.j2
11-
roles/app/templates/pvc-database.yaml.j2
12-
roles/app/templates/ingress.yaml.j2
13-
roles/app/templates/deployment.yaml.j2
10+
roles/ess/templates/pvc-log.yaml.j2
11+
roles/ess/templates/pvc-database.yaml.j2
12+
roles/ess/templates/ingress.yaml.j2
13+
roles/ess/templates/deployment.yaml.j2
1414

1515
rules:
1616
indentation:

parameters-local.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,5 @@ ess_service_account: account-server
66
ess_ws_hostname: account-server-ess
77
ess_cert_issuer:
88

9-
r_user: "{{ lookup('env', 'IM_DEV_ESS_STREAM_USER') | default('eventstream', True) }}"
10-
r_password: "{{ lookup('env', 'IM_DEV_ESS_STREAM_PASSWORD') }}"
11-
12-
ess_ampq_url: amqp://{{ r_user }}:{{ r_password }}@rabbit.im-infra.svc.cluster.local:5672/as?heartbeat=90
13-
149
ess_pull_policy_always: yes
1510
ess_priority_class: im-application-high

parameters-template.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ ess_namespace: SetMe
1010
ess_image_tag: SetMe
1111
ess_service_account: SetMe
1212
ess_ws_hostname: SetMe
13-
ess_ampq_url: SetMe
1413

1514
ess_shared_volume_volume_storageclass: SetMe
1615
ess_log_volume_volume_storageclass: SetMe

roles/app/tasks/undeploy.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
- ess_service_account != 'SetMe'
1212
- ess_ws_hostname | length > 0
1313
- ess_ws_hostname != 'SetMe'
14-
- ess_ampq_url | length > 0
15-
- ess_ampq_url != 'SetMe'
1614

1715
# Check the namespace and other basic materials
1816

@@ -39,6 +37,27 @@
3937
that:
4038
- sa_result.resources | length == 1
4139

40+
- name: Get RabbitMQ Secret
41+
kubernetes.core.k8s_info:
42+
kind: Secret
43+
name: rabbitmq
44+
namespace: "{{ ess_namespace }}"
45+
register: s_result
46+
47+
- name: Insist that we have secrets
48+
ansible.builtin.assert:
49+
that:
50+
- s_result.resources | length == 1
51+
52+
- name: Set ESS RabbitMQ credentials
53+
ansible.builtin.set_fact:
54+
rmq_user: "{{ s_result.resources[0].data.vhost_es_user | b64decode }}"
55+
rmq_password: "{{ s_result.resources[0].data.vhost_es_user_password | b64decode }}"
56+
57+
- name: Set ESS RabbitMQ url
58+
ansible.builtin.set_fact:
59+
ampq_url: amqp://{{ rmq_user }}:{{ rmq_password }}@rabbit.{{ ess_namespace }}.svc.cluster.local:{{ ess_rmq_port }}/as?heartbeat=90
60+
4261
# Ok - looks like everything's set up. Let's deploy the ESS
4362

4463
- name: Deploy PVCs ({{ ess_namespace }})
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
---
22

3-
- include_tasks: prep.yaml
3+
- name: Prep
4+
include_tasks: prep.yaml
45

56
- name: Assert authentication
6-
assert:
7+
ansible.builtin.assert:
78
that:
89
- kubeconfig | string | length > 0
910
msg: "Define KUBECONFIG"
1011

1112
- name: Display kubeconfig
12-
debug:
13+
ansible.builtin.debug:
1314
var: kubeconfig
1415

1516
# Go...
@@ -22,7 +23,7 @@
2223
block:
2324

2425
- name: Deploy
25-
include_tasks: deploy.yaml
26+
ansible.builtin.include_tasks: deploy.yaml
2627

2728
- name: Undeploy block
2829
when: ess_state == 'absent'
@@ -32,4 +33,4 @@
3233
block:
3334

3435
- name: Undeploy
35-
include_tasks: undeploy.yaml
36+
ansible.builtin.include_tasks: undeploy.yaml
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
# Expose ansible version
66
- name: Display Ansible version
7-
debug:
7+
ansible.builtin.debug:
88
var: ansible_version.full
99

1010
# Expose all the installed Python modules...
1111

1212
- name: Capture pip freeze
13-
command: pip freeze
13+
ansible.builtin.command: pip freeze
1414
register: freeze
1515
changed_when: false
1616

1717
- name: Display pip freeze
18-
debug:
18+
ansible.builtin.debug:
1919
var: freeze.stdout_lines
2020

2121
# Kubernetes credentials ------------------------------------------------------
@@ -25,5 +25,5 @@
2525
# expected environment variables so that we can assert they've been set.
2626

2727
- name: Set initial authentication facts
28-
set_fact:
28+
ansible.builtin.set_fact:
2929
kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}"

roles/ess/tasks/undeploy.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
3+
- name: Remove Event Stream
4+
kubernetes.core.k8s:
5+
definition: "{{ lookup('template', item) }}"
6+
wait: yes
7+
state: absent
8+
loop:
9+
- ingress.yaml.j2
10+
- service-ws.yaml.j2
11+
- service-api.yaml.j2
12+
- deployment.yaml.j2
13+
- pvc-database.yaml.j2
14+
- pvc-log.yaml.j2
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ spec:
7373
name: logs
7474
env:
7575
- name: ESS_AMPQ_URL
76-
value: '{{ ess_ampq_url }}'
76+
value: '{{ ampq_url }}'
7777
- name: ESS_INGRESS_LOCATION
7878
value: '{{ ess_ws_hostname }}'
7979
- name: ESS_INGRESS_SECURE

0 commit comments

Comments
 (0)