forked from Scifabric/pybossa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yml
209 lines (176 loc) · 6.33 KB
/
playbook.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
---
# Installation steps for every Ubuntu 18.04
- hosts: all
become: true
become_method: sudo
vars:
pybossa_user: "vagrant"
pybossa_path: "/vagrant"
vagrant_home: "/home/vagrant"
virtualenv_path: "/home/vagrant/pybossa-env"
redis_host: "127.0.0.1"
redis_port: "6379"
schedule_interval: "60"
tasks:
- name: Check Ubuntu 18.04 running
assert:
that:
- ansible_distribution == 'Ubuntu'
- ansible_distribution_release == 'bionic'
- name: update apt cache
apt: update_cache=yes
- name: install git
apt: name=git-core state=latest
- name: install Python
apt: name={{item}} state=latest
with_items:
- python
- python-setuptools
- python3-dev
- python3-pip
- python3-virtualenv
- python3-venv
- name: install PYBOSSA build requirements
apt: name={{item}} state=latest
with_items:
- build-essential
- libjpeg-dev
- libssl-dev
- swig
- libffi-dev
- dbus
- libdbus-1-dev
- libdbus-glib-1-dev
- libsasl2-dev
- libldap2-dev
- libssl-dev
- libldap2-dev
- name: install PostgreSQL
apt: name={{item}} state=latest
with_items:
- postgresql
- postgresql-server-dev-all
- libpq-dev
- python-psycopg2
- name: start PostgreSQL service
service: name=postgresql state=started
- name: install Redis
apt: name=redis-server state=latest
- name: start Redis service
service: name=redis-server state=started
- name: install Redis Sentinel
apt: name=redis-sentinel state=latest
- name: copy Redis Sentinel config
copy: src={{pybossa_path}}/contrib/redis/sentinel.conf dest=/etc/redis/sentinel.conf owner=redis group=redis mode=644
- name: copy Redis Sentinel systemd config
copy: src={{pybossa_path}}/contrib/redis/redis-sentinel.service dest=/etc/systemd/system/redis-sentinel.service owner=root group=root mode=755
- name: start Sentinel and enable it at boot
service: name=redis-sentinel state=started enabled=yes
- name: "install PYBOSSA virtualenv packages, can take some time..."
become_user: "{{pybossa_user}}"
pip:
chdir: "{{pybossa_path}}"
requirements: /vagrant/requirements.txt
virtualenv: /vagrant/pybossa-env
virtualenv_command: /usr/bin/python3 -m venv
virtualenv_site_packages: yes
- name: check alembic.ini existing
stat: path={{pybossa_path}}/alembic.ini
register: check_alembic
- name: copy alembic template when not existing
command: cp -p {{pybossa_path}}/alembic.ini.template {{pybossa_path}}/alembic.ini
when: not check_alembic.stat.exists
- name: check settings_local.py existing
stat: path={{pybossa_path}}/settings_local.py
register: check_settings
- name: copy settings_local template when not existing
command: cp -p {{pybossa_path}}/settings_local.py.tmpl {{pybossa_path}}/settings_local.py
when: not check_settings.stat.exists
# http://stackoverflow.com/a/16783253
# psql -lqt | cut -d \| -f 1 | grep -w <db_name>
- name: check if pybossa DB already existing
become_user: postgres
shell: "psql -lqt | cut -d \\| -f 1 | grep -w pybossa"
register: pybossa_db_exists
changed_when: False
failed_when: not (pybossa_db_exists.rc == 0 or pybossa_db_exists.rc == 1)
- name: create DB user pybossa
become_user: postgres
postgresql_user:
name: pybossa
password: tester
encrypted: yes
role_attr_flags: CREATEDB,NOSUPERUSER
- name: create PYBOSSA DB
become_user: postgres
postgresql_db: name=pybossa
owner=pybossa
encoding='UTF-8'
lc_collate='en_US.UTF-8'
lc_ctype='en_US.UTF-8'
template='template0'
# Populate DB (create tables) only when not existing.
- name: populate PYBOSSA DB
become_user: "{{pybossa_user}}"
command: "{{virtualenv_path}}/bin/python {{pybossa_path}}/cli.py db_create"
when: pybossa_db_exists.rc != 0
- name: create PYBOSSA DB test user
become_user: postgres
postgresql_user:
name: rtester
password: rtester
encrypted: true
role_attr_flags: CREATEDB,NOSUPERUSER
- name: create PYBOSSA Test DB
become_user: postgres
postgresql_db: name=pybossa_test
owner=rtester
encoding='UTF-8'
lc_collate='en_US.UTF-8'
lc_ctype='en_US.UTF-8'
template='template0'
- name: install Supervisor
apt: name=supervisor
- name: start Supervisor service
service: name=supervisor state=started
- name: copy rq-worker config
template: src=templates/rq-worker.conf.j2 dest=/etc/supervisor/conf.d/rq-worker.conf owner=root group=root
notify:
- restart supervisor
- name: copy rq-scheduler config
template: src=templates/rq-scheduler.conf.j2 dest=/etc/supervisor/conf.d/rq-scheduler.conf owner=root group=root
notify:
- restart supervisor
# activate virtualenv always in .bashrc
- name: virtualenv usage by default on bash login
become_user: "{{pybossa_user}}"
lineinfile:
dest={{vagrant_home}}/.bashrc
line=". {{virtualenv_path}}/bin/activate"
owner=vagrant
state=present
insertafter=EOF
create=yes
# activate virtualenv ->line redis-server {{pybossa_path}}/contrib/sentinel.conf --sentinel added
- name: virtualenv usage by default on bash login
become_user: "{{pybossa_user}}"
lineinfile:
dest={{vagrant_home}}/.bashrc
line="redis-server {{pybossa_path}}/contrib/sentinel.conf --sentinel"
owner=vagrant
state=present
insertafter=EOF
create=yes
- name: go to /vagrant directory on bash login
lineinfile:
dest={{vagrant_home}}/.bashrc
line="cd {{pybossa_path}}"
owner=vagrant
state=present
insertafter=EOF
handlers:
- name: restart supervisor
command: supervisorctl reread
notify: update supervisor
- name: update supervisor
command: supervisorctl update