forked from opendevshop/devshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbook.yml
346 lines (286 loc) · 10.4 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
##
# DevShop: DevMaster Role.
#
---
- hosts: all
user: root
roles:
- aegir
vars_files:
- vars.yml
- vars.{{ ansible_os_family }}.yml
vars:
devmaster_install_command: "{{ drush_path }} devshop-install {{ server_hostname }} --version={{ devshop_version }} --aegir_db_pass={{ mysql_root_password }} --aegir_db_user=root --makefile={{ devshop_makefile }} --profile=devmaster --aegir_host={{ server_hostname }} --http_service_type={{ server_webserver }} {{ devshop_working_copy }} -y"
tasks:
- hostname: name={{ server_hostname }}
- name: Setup | Message of the day.
action: template src=templates/motd.j2 dest={{ motd_path }} mode=755
# DEBIAN
- name: Setup | DEBIAN | Install common packages.
action: apt pkg={{ item }} state=installed update_cache=yes
when: ansible_os_family == "Debian"
with_items: packages
- name: Setup | DEBIAN | Install NGINX server packages.
action: apt pkg={{ item }} state=installed update_cache=yes
when: ansible_os_family == "Debian" and server_webserver == "nginx"
with_items: nginx_packages
- name: Setup | DEBIAN | Install Apache server packages.
action: apt pkg={{ item }} state=installed update_cache=yes
when: ansible_os_family == "Debian" and server_webserver == "apache"
with_items: apache_packages
# REDHAT
- name: Setup | REDHAT | Install common packages.
action: yum name={{ item }} state=present
when: ansible_os_family == "RedHat"
with_items: packages
- name: Setup | REDHAT | Install web server packages.
action: yum name={{ item }} state=present
when: ansible_os_family == "RedHat" and server_webserver == "nginx"
with_items: nginx_packages
- name: Setup | REDHAT | Install web server packages.
action: yum name={{ item }} state=present
when: ansible_os_family == "RedHat" and server_webserver == "apache"
with_items: apache_packages
- name: Add aegir to apache group.
when: server_webserver == "apache"
user:
name=aegir
groups={{ apache_user }}
append=yes
- name: Add aegir to nginx group.
when: server_webserver == "nginx"
user:
name=aegir
groups={{ nginx_user }}
append=yes
- name: Setup | Install Composer
shell: "curl -sS https://getcomposer.org/installer | php; mv composer.phar {{ local_bin_path }}/composer"
args:
creates: "{{ local_bin_path }}/composer"
- name: Setup | Prepare composer directory
file:
path=/usr/share/composer
state=directory
- name: Setup | Install Drush
shell: "{{ local_bin_path }}/composer global require drush/drush:{{ drush_version }} -d /usr/share/composer; /usr/share/composer/vendor/bin/drush"
- name: Setup | Add composer bin to path
command: sed -i '1i export PATH="/usr/share/composer/vendor/bin:$PATH"' {{ bashrc_path }}
- name: Make drush available globally.
file:
src=/usr/share/composer/vendor/bin/drush
dest="{{ local_bin_path }}/drush"
state=link
force=yes
- name: Make devshop CLI available globally.
file:
src={{ playbook_path }}/bin/devshop
dest={{ devshop_cli_path }}
state=link
force=yes
# DEBIAN only. RedHat has rewrite enabled by default.
- name: Enable mod rewrite
command: a2enmod rewrite
when: ansible_os_family == "Debian" and server_webserver == "apache"
- name: Enable mod ssl
command: a2enmod ssl
when: ansible_os_family == "Debian" and server_webserver == "apache"
# Apache Symlink for 14.04 and higher.
- name: Symbolic link to Aegir's Apache Config
when: server_webserver == "apache" and (ansible_distribution != "Ubuntu" or ansible_lsb.major_release|int >= 14)
file:
src=/var/aegir/config/apache.conf
dest={{ apache_confd_path }}
state=link
force=yes
- name: Symbolic link to Aegir's Apache Config (When ubuntu < 14.04)
when: server_webserver == "apache" and ansible_os_family == "Debian" and ansible_lsb.major_release|int < 14
file:
src=/var/aegir/config/apache.conf
dest=/etc/apache2/conf.d/aegir.conf
state=link
force=yes
# Nginx Symlink for 14.04 and higher.
- name: Symbolic link to Aegir's Nginx Config
when: server_webserver == "nginx" and (ansible_distribution != "Ubuntu" or ansible_lsb.major_release|int >= 14)
file:
src=/var/aegir/config/nginx.conf
dest={{ nginx_confd_path }}
state=link
force=yes
- name: Override Nginx Config (When ansible_os_family == "RedHat")
when: server_webserver == "nginx" and ansible_os_family == "RedHat"
template:
src=templates/nginx.conf.Redhat.j2
dest={{ nginx_conf_path }}
mode=0644
force=yes
- name: Symbolic link to Aegir's Nginx Config (When ubuntu < 14.04)
when: server_webserver == "nginx" and (ansible_os_family == "Debian" and ansible_lsb.major_release|int < 14)
file:
src=/var/aegir/config/nginx.conf
dest=/etc/nginx/sites-enabled/aegir.conf
state=link
force=yes
- name: Write nginx-pool.conf file.
when: server_webserver == "nginx"
template:
src=templates/nginx-pool.conf.j2
dest={{ nginx_www_pool_path }}
mode=0644
- name: Write php.ini file.
when: server_webserver == "apache"
template:
src=templates/php.ini.j2
dest={{ apache_php_ini_path }}
mode=0644
- name: Write php.ini file.
when: server_webserver == "nginx"
template:
src=templates/php.ini.j2
dest={{ nginx_php_ini_path }}
mode=0644
- name: Write my.cnf file.
template:
src=templates/my.cnf.{{ ansible_os_family }}.j2
dest={{ mysql_cnf_path }}
mode=0644
- name: Ensure MySQL is started and enabled on boot.
service:
name={{ mysql_daemon }}
state=started
enabled=yes
- name: Check for secured installation of MySQL
stat: path=/var/mysql-secured
register: mysqlsecured
- name: Install MySQL Securely
include: ./tasks/mysql-secure.yml
when: not mysqlsecured.stat.exists
- name: Add aegir to sudoers for restarting apache.
template:
src=templates/sudoers-d-aegir.j2
dest=/etc/sudoers.d/aegir
mode=0440
validate='visudo -cf %s'
- name: Create /var/aegir/.drush
file:
path=/var/aegir/.drush
owner=aegir group=aegir mode=0744
state=directory
- name: Create /var/aegir/.drush/commands
file:
path=/var/aegir/.drush/commands
owner=aegir group=aegir mode=0744
state=directory
- name: Install devshop_provision from github.
git:
repo: "{{ devshop_provision_repo }}"
dest: /var/aegir/.drush/commands/devshop_provision
version: "{{ devshop_version }}"
force: yes
update: yes
become: yes
become_user: aegir
- name: Make sure devshop_provision is owned by aegir
file:
path: /var/aegir/.drush/commands/devshop_provision
owner: aegir
group: aegir
recurse: yes
- name: Install required drush packages.
command: "{{ drush_path }} dl {{ item.key }}-{{ item.value }} --destination=/var/aegir/.drush/commands --package-handler={{ drush_dl_method }} -y"
with_dict: "{{ devshop_drush_packages }}"
# Runs the drush devshop-install command with all of our options:
- debug: msg="{{ devmaster_install_command }}"
- name: Install Devmaster
become: yes
become_user: aegir
command: "{{ devmaster_install_command }}"
args:
creates: /var/aegir/.drush/hostmaster.alias.drushrc.php
- name: Supervisor | Set up queue runner script
when: supervisor_running == true
template:
src=templates/hosting-queue-runner.j2
dest=/usr/bin/hosting-queue-runner
mode=0700
owner=aegir
group=aegir
- name: Supervisor | Set up supervisor job
when: supervisor_running == true
template:
src=templates/supervisor-hosting-queue-runner.conf.j2
dest={{ supervisor_hosting_queued_conf_path }}
mode=0644
notify:
- restart supervisor
- name: Service | Ensure Supervisor is restarted
when: supervisor_running == true
service:
name={{ supervisor_daemon }}
state=restarted
sleep=5
enabled=yes
- name: Service | Ensure Apache is restarted
when: server_webserver == "apache"
service:
name={{ apache_daemon }}
state=restarted
enabled=yes
- name: Service | Ensure Nginx is restarted
when: server_webserver == "nginx"
service:
name={{ nginx_daemon }}
state=restarted
enabled=yes
- name: Service | Ensure PHP Fast Process Manager is restarted
when: server_webserver == "nginx"
service:
name={{ fpm_daemon }}
state=restarted
enabled=yes
- name: Save SSH key as variable
shell: "{{ drush_path }} @hostmaster vset devshop_public_key \"$(cat ~/.ssh/id_rsa.pub)\" --yes"
become: yes
become_user: aegir
- name: Ensure privacy of SSH Keys
file: path=/var/aegir/{{ item.path }} mode={{ item.mode }}
with_items:
- { path: '.ssh', mode: '0700' }
- { path: '.ssh/id_rsa', mode: '600' }
- { path: '.ssh/id_rsa.pub', mode: '644' }
- name: Set git user name and email
shell: "git config --global user.email aegir@{{ server_hostname }}"
become: yes
become_user: aegir
- name: Set git user name and email
shell: "git config --global user.name DevShop"
become: yes
become_user: aegir
- name: Set git user name and email
shell: "git config --global push.default simple"
become: yes
become_user: aegir
- name: Clear the drush cache.
command: "{{ drush_path }} cc drush"
become: yes
become_user: aegir
handlers:
- name: restart supervisor
service:
name={{ supervisor_daemon }}
state=restarted
sleep=3
- name: restart mysql
service: >
name={{ mysql_daemon }}
state=restarted
- name: restart apache
when: conf.stat.exists
service:
name={{ apache_daemon }}
state=restarted
- name: restart nginx
when: conf.stat.exists
service:
name={{ nginx_daemon }}
state=restarted