-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.yml
75 lines (63 loc) · 2.09 KB
/
main.yml
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
---
- name: "Update last operation"
asb_last_operation:
description: "0%: Starting"
when: in_cluster
- when: apb_action == 'update'
block:
- name: Backup database
shell: kubectl exec -i -n {{ namespace }} {{ app_pod_name }} -- /bin/bash -c "mkdir -p /tmp/db && pg_dumpall -f /tmp/db/dump"
- name: Rsync to APB
shell: oc rsync -n {{ namespace }} {{ app_pod_name }}:/tmp/db /tmp
- name: Take down old deployment and pvc (if it exists)
k8s:
state: absent
definition: "{{ lookup('template', item) | from_yaml }}"
loop:
- pvc.yaml.j2
- deployment.yaml.j2
- name: "Update last operation"
asb_last_operation:
description: "25%: Backup complete"
when: in_cluster
- name: "Set postgresql objects state={{ state }}"
k8s:
state: "{{ state }}"
definition: "{{ lookup('template', item.name) | from_yaml }}"
when: item.apply | default(True)
loop:
- name: service.yaml.j2
- name: pvc.yaml.j2
apply: "{{ (_apb_plan_id == 'prod') | bool }}"
- name: deployment.yaml.j2
- name: "Update last operation"
asb_last_operation:
description: "50%: Objects updated state={{ state }}"
when: in_cluster
- when: apb_action == 'update'
block:
- name: "Wait for deployment to become available"
debug:
msg: "Deployment available status: {{ deployment_query }}"
retries: 25
delay: 10
until:
- deployment_query
- name: rsync db backup to new pod
shell: oc rsync -n {{ namespace }} /tmp/db {{ app_pod_name }}:/tmp
- name: Restore database
shell: kubectl exec -i -n {{ namespace }} {{ app_pod_name }} -- /bin/bash -c "psql -f /tmp/db/dump"
- name: encode bind credentials
asb_encode_binding:
fields:
DB_TYPE: postgres
DB_HOST: "{{ app_name }}"
DB_PORT: "5432"
DB_USER: "{{ postgresql_user }}"
DB_PASSWORD: "{{ postgresql_password }}"
DB_NAME: "{{ postgresql_database }}"
when: in_cluster and state == 'present'
- name: "Update last operation"
asb_last_operation:
description: "100%: Done"
when: in_cluster