|
1 --- |
|
2 - hosts: all |
|
3 |
|
4 vars: |
|
5 |
|
6 # These are the Wordpress database settings |
|
7 db_name: corpus |
|
8 db_user: corpus |
|
9 db_password: md5bf687edf8c06f3f1aa3759c82c1217a0 |
|
10 |
|
11 site_name: corpus-parole.local |
|
12 |
|
13 tasks: |
|
14 # - name: install language pack |
|
15 # command: localedef -v -c -i en_US -f UTF-8 en_US.UTF-8 |
|
16 |
|
17 - name: set hostname |
|
18 hostname: name={{site_name}} |
|
19 |
|
20 - name: ensure correct locale LC_ALL |
|
21 lineinfile: dest=/etc/sysconfig/i18n regexp=^LC_ALL= line=LC_ALL="en_US.UTF-8" |
|
22 - name: ensure correct locale LANG |
|
23 lineinfile: dest=/etc/sysconfig/i18n regexp=^LANG= line=LANG="en_US.UTF-8" |
|
24 |
|
25 - name: set .bashrc |
|
26 copy: src=files/.bashrc dest=/home/vagrant/.bashrc force=yes |
|
27 - name: set .profile |
|
28 copy: src=files/.profile dest=/home/vagrant/.profile force=yes |
|
29 |
|
30 - name: yum update |
|
31 yum: name=* update_cache=yes state=latest |
|
32 |
|
33 - name: repo ignore outdated postgres base |
|
34 ini_file: |
|
35 dest: /etc/yum.repos.d/CentOS-Base.repo |
|
36 section: base |
|
37 option: exclude=postgresql* |
|
38 |
|
39 - name: repo ignore outdated postgres update |
|
40 ini_file: |
|
41 dest: /etc/yum.repos.d/CentOS-Base.repo |
|
42 section: updates |
|
43 option: exclude=postgresql* |
|
44 |
|
45 - name: additional repos install |
|
46 yum: name={{item}} state=latest |
|
47 with_items: |
|
48 - epel-release |
|
49 - centos-release-SCL |
|
50 |
|
51 # Remi yum repository. |
|
52 - stat: path=/etc/yum.repos.d/remi.repo |
|
53 register: remi_repo |
|
54 |
|
55 - name: Download Remi repo. |
|
56 get_url: url=http://rpms.famillecollet.com/enterprise/remi-release-6.rpm dest=/tmp/ |
|
57 when: remi_repo.stat.exists == False |
|
58 |
|
59 - name: Install Remi repo. |
|
60 command: rpm -Uvh --force /tmp/remi-release-6.rpm creates=/etc/yum.repos.d/remi.repo |
|
61 |
|
62 - name : delete remi rpm |
|
63 file: path=/tmp/remi-release-6.rpm state=absent |
|
64 |
|
65 # postgres yum repository. |
|
66 - stat: path=/etc/yum.repos.d/pgdg-94-centos.repo |
|
67 register: postgres_repo |
|
68 |
|
69 - name: Download Postgres repo. |
|
70 get_url: url=http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm dest=/tmp/ |
|
71 when: postgres_repo.stat.exists == False |
|
72 |
|
73 - name: Install postgres repo. |
|
74 command: rpm -Uvh --force /tmp/pgdg-centos94-9.4-1.noarch.rpm creates=/etc/yum.repos.d/pgdg-94-centos.repo |
|
75 |
|
76 - name : delete postgres rpm |
|
77 file: path=/tmp/pgdg-centos94-9.4-1.noarch.rpm state=absent |
|
78 |
|
79 - name: additional repos install epel |
|
80 ini_file: |
|
81 dest: /etc/yum.repos.d/epel.repo |
|
82 section: epel |
|
83 option: enabled |
|
84 value: 1 |
|
85 |
|
86 - name: yum update after repos |
|
87 yum: name=* update_cache=yes state=latest |
|
88 |
|
89 #TODO install alternative packages |
|
90 - name: install libs |
|
91 yum: name={{item}} state=latest enablerepo=remi |
|
92 with_items: |
|
93 - nginx |
|
94 - postgresql94-server |
|
95 - python-psycopg2 |
|
96 - htop |
|
97 - openssl |
|
98 - php |
|
99 - php-cli |
|
100 - php-fpm |
|
101 - php-mbstring |
|
102 - php-mcrypt |
|
103 - php-curl |
|
104 - php-gd |
|
105 - php-json |
|
106 - php-pgsql |
|
107 - php-xml |
|
108 - java-1.8.0-openjdk |
|
109 - tomcat6 |
|
110 |
|
111 #TODO: check php-fpm config in /etc/php5/fpm/... |
|
112 |
|
113 # - name: Start the services |
|
114 # service: name={{item}} state=started enabled=true |
|
115 # with_items: |
|
116 # - postgres |
|
117 # - nginx |
|
118 # - tomcat |
|
119 |
|
120 ## php-fpm config |
|
121 |
|
122 # set fpm user to nginx |
|
123 # authoroze /var/log/php-fpm |
|
124 - name: copy sysconfig for php-fpm |
|
125 copy: src=files/sysconfig_php-fpm dest=/etc/sysconfig/php-fpm |
|
126 - name: set /var/log/php-fpm permission |
|
127 file: path=/var/log/php-fpm/ state=directory owner=nginx group=nginx |
|
128 |
|
129 - name: set php-fpm listen to socket |
|
130 lineinfile: |
|
131 dest: /etc/php-fpm.d/www.conf |
|
132 regexp: '^listen\s*=' |
|
133 line: 'listen = /var/run/php-fpm/php-fpm.sock' |
|
134 state: present |
|
135 |
|
136 - name: set php-fpm user |
|
137 lineinfile: |
|
138 dest: /etc/php-fpm.d/www.conf |
|
139 regexp: '^user\s*=' |
|
140 line: 'user = nginx' |
|
141 state: present |
|
142 |
|
143 - name: set php-fpm group |
|
144 lineinfile: |
|
145 dest: /etc/php-fpm.d/www.conf |
|
146 regexp: '^group\s*=' |
|
147 line: 'group = nginx' |
|
148 state: present |
|
149 |
|
150 - name: set php-fpm user |
|
151 lineinfile: |
|
152 dest: /etc/php-fpm.d/www.conf |
|
153 regexp: '^;listen.owner\s*=' |
|
154 line: 'listen.owner = nginx' |
|
155 state: present |
|
156 |
|
157 - name: set php-fpm group |
|
158 lineinfile: |
|
159 dest: /etc/php-fpm.d/www.conf |
|
160 regexp: '^;listen.group\s*=' |
|
161 line: 'listen.group = nginx' |
|
162 state: present |
|
163 |
|
164 - name: set php-fpm permission |
|
165 lineinfile: |
|
166 dest: /etc/php-fpm.d/www.conf |
|
167 regexp: '^;listen.mode\s*=' |
|
168 line: 'listen.mode = 0660' |
|
169 state: present |
|
170 |
|
171 |
|
172 - name: restart php-fpm |
|
173 service: name=php-fpm state=restarted enabled=yes |
|
174 |
|
175 |
|
176 ## nginx config |
|
177 |
|
178 - name: create ssl folder |
|
179 file: path=/etc/nginx/ssl state=directory mode=0700 |
|
180 - name: generate ssl key |
|
181 command: openssl genrsa -out "/etc/nginx/ssl/{{ site_name }}.key" 1024 |
|
182 args: |
|
183 creates: /etc/nginx/ssl/{{ site_name }}.key |
|
184 - name: generate ssl csr |
|
185 command: openssl req -new -key /etc/nginx/ssl/{{ site_name }}.key -out /etc/nginx/ssl/{{ site_name }}.csr -subj "/CN={{ site_name }}/O=Vagrant/C=UK" |
|
186 args: |
|
187 creates: /etc/nginx/ssl/{{ site_name }}.csr |
|
188 - name: generate ssl certificate |
|
189 command: openssl x509 -req -days 365 -in /etc/nginx/ssl/{{ site_name }}.csr -signkey /etc/nginx/ssl/{{ site_name }}.key -out /etc/nginx/ssl/{{ site_name }}.crt |
|
190 args: |
|
191 creates: /etc/nginx/ssl/{{ site_name }}.crt |
|
192 |
|
193 - name: change nginx default |
|
194 template: src=files/site.j2 dest=/etc/nginx/nginx.conf mode=0644 force=yes |
|
195 |
|
196 - name: restart nginx |
|
197 service: name=nginx state=restarted enabled=yes |
|
198 |
|
199 |
|
200 ## postgres |
|
201 - name: set postgresql to start |
|
202 service: name=postgresql-9.4 enabled=yes |
|
203 |
|
204 - name: postgresql initdb |
|
205 command: service postgresql-9.4 initdb |
|
206 args: |
|
207 creates: /var/lib/pgsql/9.4/data/postgresql.conf |
|
208 |
|
209 ## configure tomcat |
|
210 |
|
211 - name: set JAVA_HOME |
|
212 lineinfile: |
|
213 dest: /etc/tomcat6/tomcat6.conf |
|
214 regexp: '^\#JAVA_HOME=' |
|
215 line: JAVA_HOME="/etc/alternatives/jre_1.8.0" |
|
216 state: present |
|
217 |
|
218 ## Install sesame |
|
219 - stat: path=/var/lib/tomcat6/webapps/openrdf-sesame.war |
|
220 register: sesame_jar |
|
221 |
|
222 - name: download sesame |
|
223 get_url: url=http://sourceforge.net/projects/sesame/files/Sesame%202/2.8.3/openrdf-sesame-2.8.3-sdk.tar.gz/download dest=/tmp/openrdf-sesame-2.8.3-sdk.tar.gz |
|
224 when: sesame_jar.stat.exists == False |
|
225 |
|
226 - name: create sesame untar dest |
|
227 file: path=/tmp/openrdf-sesame-2.8.3-sdk state=directory |
|
228 when: sesame_jar.stat.exists == False |
|
229 |
|
230 - name: unarchive sesame |
|
231 unarchive: src=/tmp/openrdf-sesame-2.8.3-sdk.tar.gz dest=/tmp/openrdf-sesame-2.8.3-sdk copy=false |
|
232 when: sesame_jar.stat.exists == False |
|
233 |
|
234 - name: deploy sesame jar |
|
235 shell: cp /tmp/openrdf-sesame-2.8.3-sdk/openrdf-sesame-2.8.3/war/*.war /var/lib/tomcat6/webapps/ |
|
236 when: sesame_jar.stat.exists == False |
|
237 |
|
238 - name: create sesame data folder |
|
239 file: path=/var/lib/sesame/data state=directory owner=tomcat group=tomcat |
|
240 when: sesame_jar.stat.exists == False |
|
241 |
|
242 - name: update tomcat config |
|
243 lineinfile: |
|
244 dest: /etc/tomcat6/tomcat6.conf |
|
245 line: 'JAVA_OPTS=\"${JAVA_OPTS} -Dinfo.aduna.platform.appdata.basedir=/var/lib/sesame/data\"' |
|
246 state: present |
|
247 when: sesame_jar.stat.exists == False |
|
248 |
|
249 - name: restart tomcat |
|
250 service: name=tomcat6 state=restarted enabled=yes |
|
251 when: sesame_jar.stat.exists == False |
|
252 |
|
253 - name : delete sesame archive |
|
254 file: path=/tmp/openrdf-sesame-2.8.3-sdk.tar.gz state=absent |
|
255 |
|
256 - name : delete sesame untar |
|
257 file: path=/tmp/openrdf-sesame-2.8.3-sdk state=absent |
|
258 |
|
259 |
|
260 #set postgresql local access to trust |
|
261 - name: add trust access for postgresql user |
|
262 lineinfile: |
|
263 dest: /var/lib/pgsql/9.4/data/pg_hba.conf |
|
264 regexp: '^host\s+all\s+postgres\s+.127\.0\.0\.1\/32\s+trust$' |
|
265 insertafter: '^#\sIPv4\slocal.+' |
|
266 line: 'host all postgres 127.0.0.1/32 trust' |
|
267 |
|
268 - name: postgresql start |
|
269 service: name=postgresql-9.4 state=started |
|
270 |
|
271 - name: Create database user |
|
272 postgresql_user: name={{ db_user }} password={{ db_password }} state=present |
|
273 sudo: yes |
|
274 sudo_user: postgres |
|
275 |
|
276 - name: create database |
|
277 postgresql_db: name={{ db_name }} encoding=utf8 owner={{ db_user }} state=present |
|
278 sudo: yes |
|
279 sudo_user: postgres |
|
280 |
|
281 - name: restart postgres |
|
282 service: name=postgresql-9.4 state=restarted |
|
283 |
|
284 ## Install dev dependencies |
|
285 |
|
286 - name: install dev tools |
|
287 yum: name="{{item}}" state=latest |
|
288 with_items: |
|
289 - "@Development tools" |
|
290 |
|
291 #install composer |
|
292 - stat: path=/usr/local/bin/composer |
|
293 register: composer_bin |
|
294 |
|
295 - name: install composer |
|
296 shell: curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin |
|
297 when: composer_bin.stat.exists == False |
|
298 - name: rename composer |
|
299 command: mv /usr/local/bin/composer.phar /usr/local/bin/composer |
|
300 when: composer_bin.stat.exists == False |
|
301 |
|
302 #install node |
|
303 - stat: path=/usr/bin/node |
|
304 register: node_bin |
|
305 |
|
306 - name: install node rpm |
|
307 shell: curl -sL https://rpm.nodesource.com/setup | bash - |
|
308 when: node_bin.stat.exists == False |
|
309 - name: install node |
|
310 yum: name=nodejs state=latest |
|
311 when: node_bin.stat.exists == False |
|
312 |
|
313 ## open ports |
|
314 - name: get iptables rules |
|
315 shell: iptables -L |
|
316 register: iptablesrules |
|
317 always_run: yes |
|
318 sudo: true |
|
319 |
|
320 - name: add nginx http iptable rule |
|
321 command: /sbin/iptables -I INPUT 1 -p tcp --dport http -j ACCEPT -m comment --comment "nginx 80" |
|
322 sudo: true |
|
323 when: iptablesrules.stdout.find("nginx 80") == -1 |
|
324 |
|
325 - name: add nginx http iptable rule |
|
326 command: /sbin/iptables -I INPUT 1 -p tcp --dport https -j ACCEPT -m comment --comment "nginx 443" |
|
327 sudo: true |
|
328 when: iptablesrules.stdout.find("nginx 443") == -1 |
|
329 |
|
330 - name: add postgresql iptable rule |
|
331 command: /sbin/iptables -I INPUT 1 -p tcp --dport 5432 -j ACCEPT -m comment --comment "postgresql" |
|
332 sudo: true |
|
333 when: iptablesrules.stdout.find("postgresql") == -1 |
|
334 |
|
335 - name: add tomcat iptable rule |
|
336 command: /sbin/iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT -m comment --comment "tomcat" |
|
337 sudo: true |
|
338 when: iptablesrules.stdout.find("tomcat") == -1 |
|
339 |
|
340 - name: save iptables |
|
341 command: service iptables save |
|
342 sudo: true |
|
343 |
|
344 - name: restart iptables |
|
345 service: name=iptables state=restarted |
|
346 sudo: true |
|
347 |
|
348 handlers: |
|
349 - name: nginx-restart |
|
350 action: service name=nginx update_cache=yes state=latest |
|
351 |
|
352 |
|
353 # - name: install nginx |
|
354 # apt: name=nginx |
|
355 # |
|
356 # - name: change nginx default |
|
357 # copy: src=files/default dest=/etc/nginx/sites-available/ mode=0644 force=yes |
|
358 # |
|
359 # - name: install software-properties-common |
|
360 # apt: name=software-properties-common |
|
361 # |
|
362 # - name: add repo |
|
363 # copy: src=files/mariadb.list dest=/etc/apt/sources.list.d/ |
|
364 # register: mariadb_repo_present |
|
365 # |
|
366 # - name: add repokey |
|
367 # command: apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db |
|
368 # when: mariadb_repo_present.changed |
|
369 # |
|
370 # - name: apt install mariadb |
|
371 # apt: name={{item}} update_cache=yes |
|
372 # with_items: |
|
373 # - mysql-common=5.1.67-mariadb122~precise |
|
374 # - libmariadbclient16=5.1.67-mariadb122~precise |
|
375 # - mariadb-client-core-5.1=5.1.67-mariadb122~precise |
|
376 # - |
|
377 # - mariadb-server |