playbook.yml
5.24 KB
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
---
# Installation steps for every Ubuntu 14.04
- hosts: all
sudo: yes
vars:
pybossa_user: "vagrant"
pybossa_path: "/vagrant"
vagrant_home: "/home/vagrant"
virtualenv_path: "/home/vagrant/pybossa-env"
tasks:
- name: Check Ubuntu 14.04 running
assert:
that:
- ansible_distribution == 'Ubuntu'
- ansible_distribution_release == 'trusty'
- 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-dev
- python-virtualenv
- python-setuptools
- python-pip
- name: install PyBossa build requirements
apt: name={{item}} state=latest
with_items:
- build-essential
- libjpeg-dev
- libssl-dev
- swig
- libffi-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
copy: src={{pybossa_path}}/contrib/redis/redis-sentinel dest=/etc/init.d/redis-sentinel owner=root group=root mode=755
- name: copy Sentinel config
copy: src={{pybossa_path}}/contrib/redis/sentinel.conf dest=/etc/redis/sentinel.conf owner=redis group=redis mode=644
- name: start Sentinel and enable it at boot
service: name=redis-sentinel state=started enabled=yes
- name: "upgrade pip itself"
sudo_user: "{{pybossa_user}}"
pip: name=pip state=latest chdir={{pybossa_path}} virtualenv={{virtualenv_path}} virtualenv_site_packages=yes
- name: "install PyBossa virtualenv packages, can take some time..."
sudo_user: "{{pybossa_user}}"
pip: chdir={{pybossa_path}} requirements={{pybossa_path}}/requirements.txt virtualenv={{virtualenv_path}} 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
sudo_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
sudo_user: postgres
postgresql_user: name=pybossa password=tester role_attr_flags=CREATEDB,NOSUPERUSER
- name: create PyBossa DB
sudo_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
sudo_user: "{{pybossa_user}}"
command: "{{virtualenv_path}}/bin/python cli.py db_create"
args:
chdir: "{{pybossa_path}}"
when: pybossa_db_exists.rc != 0
- name: create PyBossa DB test user
sudo_user: postgres
postgresql_user: name=rtester password=rtester role_attr_flags=CREATEDB,NOSUPERUSER
- name: create PyBossa Test DB
sudo_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 Supervisor config
template: src=templates/rq-worker.conf.j2 dest=/etc/supervisor/conf.d/rq-worker.conf owner=root group=root
notify:
- restart supervisor
# activate virtualenv always in .bashrc
- name: virtualenv usage by default on bash login
sudo_user: "{{pybossa_user}}"
lineinfile:
dest={{vagrant_home}}/.bashrc
line=". {{virtualenv_path}}/bin/activate"
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
service: name=supervisor state=restarted