forked from techjoomla/infra-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-site.yml
186 lines (153 loc) · 5.46 KB
/
create-site.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
---
- hosts: "{{which_host}}"
vars_files: ["vars/default.yml"]
vars_prompt:
- name: "which_host"
prompt: "Which host to run this on ?"
private: no
- name: "site_id"
prompt: "Site ID (Used as the FPM pool, Apache vhost and NGINX vhost"
private: no
- name: "php_install_version"
prompt: "PHP Version. Available options are 5.6 or 7.0"
private: no
tasks:
- name: Set domain
set_fact:
site_server_name: "{{site_server_name | default([]) }} + {{ [site_domain] }}"
when: site_domain is defined
- name: Set upstreams
set_fact:
upstreams:
- { name: "{{ site_id }}", config_lines: [], ip: ["127.0.0.1:80"] }
when: upstreams is not defined
- name: Create site directory
file:
path: "{{sites_container}}/{{site_server_name[0] | mandatory}}"
state: directory
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"
- name: Create log directory
file:
path: "{{sites_container}}/{{site_server_name[0] | mandatory}}/logs"
state: directory
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"
- name: Create log directory
file:
path: "/var/log/nginx/{{ site_id }}"
state: directory
- name: Create tmp directory
file:
path: "{{sites_container}}/{{site_server_name[0] | mandatory}}/tmp"
state: directory
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"
- name: Create run directory
file:
path: "{{sites_container}}/{{site_server_name[0] | mandatory}}/run"
state: directory
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"
- name: Create public directory
file:
path: "{{sites_container}}/{{site_server_name[0]}}/public"
state: directory
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"
- name: Create Welcome file
template:
src: "templates/welcome.j2"
dest: "{{ sites_container }}/{{ site_server_name[0] | mandatory }}/public/index.php"
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"
- name: Create FPM pool
template:
src: "templates/fpm-primary.j2"
dest: "/etc/php/{{php_install_version}}/fpm/pool.d/{{site_id}}.conf"
- name: Create FPM pool config directory
file: path="/etc/php/{{php_install_version}}/fpm/pool.d/{{site_id}}.d" state=directory
- name: Create FPM pool config
template:
src: "templates/fpm-secondary.j2"
dest: "/etc/php/{{php_install_version}}/fpm/pool.d/{{site_id}}.d/main.conf"
- name: Create Apache vhost
template:
src: "templates/apache-primary.j2"
dest: "/etc/apache2/sites-enabled/{{site_id | mandatory}}.conf"
- name: Create Apache vhost config directory
file: path="/etc/apache2/sites-enabled/{{site_id | mandatory}}.d" state=directory
- name: Create Apache vhost config
template:
src: "templates/apache-secondary.j2"
dest: "/etc/apache2/sites-enabled/{{site_id}}.d/main.conf"
- name: Create NGINX vhost
template:
src: "templates/nginx-primary.j2"
dest: "{{ nginx_vhosts_location }}/{{site_id}}.conf"
- name: Create NGINX vhost config directory
file: path="{{ nginx_vhosts_location }}/{{site_id}}.d" state=directory
- name: Create NGINX vhost config
template:
src: "templates/nginx-secondary.j2"
dest: "{{ nginx_vhosts_location }}/{{site_id}}.d/main.conf"
- name: Create SSL directory
file:
dest: /etc/nginx/ssl
state: directory
when: site_ssl == 1
- name: Copy self-signed SSL key
copy:
dest: /etc/nginx/ssl/{{site_server_name[0]}}.key
src: "{{ssl_key_file_path}}"
mode: 0644
when: site_ssl == 1 and ssl_selfsigned != 1
- name: Copy self-signed SSL cert
copy:
dest: /etc/nginx/ssl/{{site_server_name[0]}}.crt
src: "{{ssl_cert_file_path}}"
mode: 0644
when: site_ssl == 1 and ssl_selfsigned != 1
- name: create self-signed SSL cert
command: openssl req -new -nodes -x509 -subj "/C=IN/ST=Maharashtra/L=Pune/O=Chacha Chaudhary and Co./CN={{site_server_name[0]}}" -days 3650 -keyout /etc/nginx/ssl/{{site_server_name[0]}}.key -out /etc/nginx/ssl/{{site_server_name[0]}}.crt
when: ssl_selfsigned == 1
become: yes
- name: Ensure hosts file entry is present
lineinfile:
dest: /etc/hosts
regexp: '{{ site_server_name[0] }}'
line: '127.0.0.1 {{ site_server_name[0] }}'
tags: devtools
- name: Restart NGINX
service: name=nginx state=restarted
become: true
- name: Restart Apache
service: name=apache2 state=restarted
become: true
- name: Restart FPM
command: "{{fpm_init_script}} restart"
become: true
- name: Create adminer directory
file:
path: "{{sites_container}}/{{site_server_name[0]}}/public/adminer"
state: directory
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"
tags:
- adminer
- name: Download Adminer
get_url:
url: "{{adminer_download_url}}"
dest: "{{ sites_container }}/{{ site_server_name[0] | mandatory }}/public/adminer/index.php"
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"
tags:
- adminer
- name: Download Adminer CSS
get_url:
url: "{{adminer_css_download_url}}"
dest: "{{ sites_container }}/{{ site_server_name[0] | mandatory }}/public/adminer/adminer.css"
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"
tags:
- adminer