-
Notifications
You must be signed in to change notification settings - Fork 6
/
deploy-backup.yml
151 lines (142 loc) · 4.98 KB
/
deploy-backup.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
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
---
- name: Deploy the infrastructure to execute and restore backups
hosts: desenvolvimento,producao
become: yes
gather_facts: no
pre_tasks:
- name: 'Install python3 and pip'
raw: apt-get -y install python3-pip python3-setuptools
tasks:
- name: Configura usuário padrão
user:
name: odoo
uid: 1040
shell: /bin/bash
groups: sudo
append: yes
password: "{{user_odoo_password}}"
- name: Cria a pasta backups
become: yes
become_user: root
file: path=/opt/backups/ state=directory mode=0755 owner=odoo
- name: Cria a pasta .aws
become: yes
become_user: root
file: path=/home/odoo/.aws/ state=directory mode=0755 owner=odoo
- copy:
src: scripts/common.py
dest: /opt/backups/common.py
owner: odoo
group: odoo
mode: 0644
- copy:
src: scripts/odoo_restore.py
dest: /opt/backups/odoo-restore.py
owner: odoo
group: odoo
mode: 0644
- copy:
src: scripts/odoo_backup.py
dest: /opt/backups/odoo-backup.py
owner: odoo
group: odoo
mode: 0644
- copy:
src: scripts/keep.sh
dest: /root/keep.sh
owner: root
group: root
mode: 0755
- template:
src: templates/aws.credentials
dest: /home/odoo/.aws/credentials
owner: odoo
group: odoo
mode: 0644
- template:
src: templates/aws.config
dest: /home/odoo/.aws/config
owner: odoo
group: odoo
mode: 0644
- pip:
executable: pip3
name: "{{ item }}"
state: present
with_items:
- awscli
- docopt
- psycopg2
- boto3
- cron:
name: "Execute backup scripts at 00:10 Brazil Time"
user: "odoo"
hour: "03"
minute: "10"
job: "python3 /opt/backups/odoo-backup.py {{ pg_user }} {{ pg_password }}"
when: inventory_hostname in groups['producao']
- name: Fire up a docker build
cron:
name: Fire up a docker build
user: odoo
hour: "03"
minute: "10"
job: "curl -H \"Content-Type: application/json\" --data '{\"docker_tag\": \"11.0\"}' -X POST https://registry.hub.docker.com/u/trustcode/docker-odoo/trigger/5074c4ae-bbac-4a0d-a694-cc0b91100055/"
when: inventory_hostname == 'trustcode-server'
- name: Update docker image 20 minutes later
cron:
name: Update docker image 20 minutes later
user: odoo
hour: "03"
minute: "30"
job: "docker pull trustcode/docker-odoo:{{ item.value.versao }}"
with_dict: "{{ docker }}"
#
# - name: Update databases with autoupdate
# cron:
# name: Update databases with autoupdate
# user: odoo
# hour: "03"
# minute: "30"
# job: "docker run --name trustcode-update-odoo-{{ item.key }} -e DATABASE='{{ item.key }}' -e PG_USER='{{ pg_user }}' -e PG_PORT={{ pg_port }} -e PG_HOST='{{ pg_host }}' -e PG_PASSWORD='{{ pg_password }}' -e DISABLE_LOGFILE=1 -e ODOO_VERSION={{ item.value.docker.versao }} -e TRUSTCODE_ENTERPRISE=1 -e ODOO_ENTERPRISE=1 --net host -v /opt/dados/{{ item.value.docker.name }}:/opt/dados -v /home/odoo/.ssh:/home/temp/.ssh trustcode/docker-odoo:{{ item.value.docker.versao }} autoupdate"
# with_dict: "{{ databases }}"
# Order here is important
- name: "Stop containers that are used to update Odoo at 03:10"
cron:
name: "Stop containers that are used to update Odoo at 03:10"
user: "odoo"
hour: "06"
minute: "30"
job: "docker stop $(docker ps -qa --no-trunc --filter \"name=trustcode-update*\")"
when: inventory_hostname in groups['producao']
- name: "Remove containers that are used to update Odoo at 03:15"
cron:
name: "Remove containers that are used to update Odoo at 03:15"
user: "odoo"
hour: "06"
minute: "35"
job: "docker rm $(docker ps -qa --no-trunc --filter \"status=exited\" --filter \"name=trustcode-update*\")"
when: inventory_hostname in groups['producao']
- name: "Remove images that are not in use at 03:20"
cron:
name: "Remove images that are not in use at 03:20"
user: "odoo"
hour: "06"
minute: "45"
job: "docker rmi $(docker images --filter \"dangling=true\" -q --no-trunc)"
when: inventory_hostname in groups['producao']
- name: "Remove old volumes that are not used anymore at 03:25"
cron:
name: "Remove old volumes that are not used anymore at 03:25"
user: "odoo"
hour: "06"
minute: "50"
job: "docker volume rm $(docker volume ls -qf dangling=true)"
when: inventory_hostname in groups['producao']
- name: "Cron to keep services running"
cron:
name: "Cron to keep services running"
user: "root"
minute: "*/1"
job: /root/keep.sh
when: inventory_hostname in groups['producao']