-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbook.yml
247 lines (212 loc) · 6.94 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
---
- hosts: all
pre_tasks:
- name: 'install python2 (because ansible needs it, but xenial does not provide it by default)'
raw: sudo apt-get update && sudo apt-get -y install python
vars_files:
- secrets_vars.yml
vars:
packages:
- python
- python3
- python-pip
- python-virtualenv
- vim
- binutils
- tree
- language-pack-pl
- postgresql-client
- redis-tools
- redis-server
- coffeescript
- libz-dev
- libjpeg-dev
- libfreetype6-dev
- python-dev
# remote_user: 'root' # TODO remote
remote_user: 'ubuntu'
# home_dir: "/{{remote_user}}" # TODO remote
home_dir: "/home/{{remote_user}}"
web_base_dir: "{{home_dir}}/better_spots"
media_dir: '/better_spots/media'
project_dir: '/better_spots'
static_root: '/var/www/static'
project_instance: 'dogspot'
celery_worker: 'better_spots'
proxy_env:
DB_PASSWORD: "{{db_password}}"
DJANGO_SECRET_KEY: "{{ django_secret_key }}"
EMAIL_HOST_PASSWORD: "{{ email_host_password }}"
EMAIL_HOST_USER: "{{email_host_user}}"
GOOGLE_MAPS_JS_API_KEY: "{{ google_maps_js_key }}"
GOOGLE_MAP_API_KEY: "{{ google_map_api_key }}"
MAILTRAP_USER: "{{ mailtrap_user }}"
MAILTRAP_PASSWORD: "{{ mailtrap_password }}"
MAILTRAP_TOKEN: "{{ mailtrap_token }}"
RECAPTCHA_PUBLIC_KEY: "{{ recaptcha_public_key }}"
RECAPTCHA_PRIVATE_KEY: "{{ recaptcha_private_key }}"
PYTHONIOENCODING: "utf-8"
gather_facts: no
environment: "{{proxy_env}}"
tasks:
- name: copy project to remote location
synchronize:
src: "../../better-spots/"
dest: "/better_spots"
tags: deploy
- name: create web_base_dir
file: path={{web_base_dir}} state=directory
tags: deploy
- name: Install packages
sudo: yes
apt: pkg={{ item }} state=present update_cache=yes
with_items: "{{ packages }}"
# http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS23UbuntuPGSQL96Apt
- name: Add PostgreSQL to the sources list
sudo: yes
apt_repository: repo='deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main'
update_cache=yes
state=present
- name: Add the PostgreSQL public GPG key to the apt repo
sudo: yes
apt_key: url=http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc
state=present
- name: Install PostgreSQL
sudo: yes
apt: name={{ item }} update_cache=yes state=installed
with_items:
- postgresql-9.6
- postgresql-9.6-postgis-2.3
- postgresql-contrib-9.6
- postgresql-9.6-postgis-scripts
- python-psycopg2
- postgis
- postgresql-9.6-pgrouting
tags: packages
- name: Ensure the PostgreSQL service is running
service: name=postgresql state=started enabled=yes
- name: Ensure database is created
become_user: postgres
become: yes
postgresql_db: name='better_spots'
encoding='UTF-8'
lc_collate='en_US.UTF-8'
lc_ctype='en_US.UTF-8'
template='template0'
state=present
- name: Ensure user has access to the database
become_user: postgres
become: yes
postgresql_user:
db: 'better_spots'
name: 'better_spots'
password: '{{db_password}}'
priv: ALL
role_attr_flags: CREATEDB,SUPERUSER
state: present
encrypted: yes
- name: Create media directories
sudo: yes
file: path="{{ item }}" state=directory
with_items:
- "{{ media_dir }}/img"
- name: Craete STATIC_ROOT
sudo: yes
file: path="{{ item }}" owner="{{remote_user}}" group="{{remote_user}}" mode=0775 state=directory
with_items:
- "{{ static_root }}"
- name: create virtualenv for python 3.5
sudo: yes
command: creates={{ web_base_dir }}/venv virtualenv -p python3.5 {{ web_base_dir }}/venv
- name: install pip packages
sudo: yes
pip:
virtualenv: "{{ web_base_dir }}/venv"
requirements: "/better_spots/requirements.txt"
tags: pipka
# TODO non-vagrant specific
# - name: create .bashrc
# file:
# path: "{{ home_dir }}/.bashrc"
# state: touch
#
# - name: create .profile
# file:
# path: "{{ home_dir }}/.profile"
# state: touch
- name: activate virtualenv, navigate to project dir
lineinfile:
dest: "{{ home_dir }}/.bashrc"
state: present
line: "{{ item }}"
with_items:
- "source {{ web_base_dir }}/venv/bin/activate"
- "cd {{ project_dir }}"
- name: save environment variables into .app_environemnts file
lineinfile:
dest: "{{ home_dir }}/.app_environemnts"
regexp: "^export {{ item.key }}"
line: "export {{ item.key }}='{{ item.value }}'"
create: yes
with_dict: "{{proxy_env}}"
- name: add sourcing the .app_environemnts file to the .profile file
lineinfile:
dest: "{{ home_dir }}/.profile"
line: "source ~/.app_environemnts"
- name: run database migrations
shell: "{{ web_base_dir }}/venv/bin/python manage.py migrate --noinput"
args:
chdir: "{{ project_dir }}"
executable: /bin/bash
- name: create project label specific tags
shell: "{{ web_base_dir }}/venv/bin/python manage.py create_tags"
args:
chdir: "{{ project_dir }}"
executable: /bin/bash
- name: create or update project label specific instance
shell: "{{ web_base_dir }}/venv/bin/python manage.py create_or_update_instance"
args:
chdir: "{{ project_dir }}"
executable: /bin/bash
- name: load spots data fixtures
shell: "{{ web_base_dir }}/venv/bin/python manage.py loaddata data/initial_spots/spots.json"
args:
chdir: "{{ project_dir }}"
executable: /bin/bash
tags: loaddata
- name: dump fresh data currently in db
shell: "{{ web_base_dir }}/venv/bin/python manage.py dumpdata core.spot --indent 2 > data/initial_spots/spots.json"
args:
chdir: "{{ project_dir }}"
executable: /bin/bash
tags: dumpdata
- name: copy images for spots and instance from fixtures
copy:
# src: ../../better-spots/data/initial_spots/initial_img/ # TODO remote
src: data/initial_spots/initial_img/
dest: "{{ media_dir }}/img"
tags: loaddata
- name: create superuser
shell: "{{ web_base_dir }}/venv/bin/python manage.py create_andi"
args:
chdir: "{{ project_dir }}"
executable: /bin/bash
tags: loaddata
- name: create objects
shell: "{{ web_base_dir }}/venv/bin/python manage.py create_objects"
args:
chdir: "{{ project_dir }}"
executable: /bin/bash
tags: loaddata
- name: compile coffescripts
sudo: yes
shell: "coffee --compile --output js/ coffee/"
args:
chdir: "{{ project_dir }}/static"
executable: /bin/bash
tags: coffee
- name: collect static
shell: "{{ web_base_dir }}/venv/bin/python manage.py collectstatic --noinput"
args:
chdir: "{{ project_dir }}"
executable: /bin/bash