Browse Source

Apache now configurable for multiple virtual domains.

Thomas Buck 5 years ago
parent
commit
3c51ebedd4

+ 1
- 0
group_vars/sovereign View File

@@ -14,6 +14,7 @@ admin_email: "{{ main_user_name }}@{{ domain }}"
14 14
 virtual_domains:
15 15
   - name: "{{ domain }}"
16 16
     pk_id: 1
17
+    doc_root: "/var/www/{{ domain }}"
17 18
 
18 19
 # mail
19 20
 mail_virtual_users:

+ 5
- 0
roles/blog/handlers/main.yml View File

@@ -0,0 +1,5 @@
1
+---
2
+# Defines handlers applicable across all machines in the infrastructure.
3
+
4
+- name: restart apache
5
+  service: name=apache2 state=restarted

+ 16
- 12
roles/blog/tasks/blog.yml View File

@@ -1,16 +1,20 @@
1
-- name: Create directory for blog HTML
2
-  file: state=directory path=/var/www/{{ domain }} group=www-data owner={{ main_user_name }}
1
+- name: Create directories for HTML documents
2
+  file: state=directory path={{ item }} group=www-data owner={{ main_user_name }}
3
+  with_items: "{{ virtual_domains | json_query('[*].doc_root') | unique }}"
3 4
 
4
-- name: Rename existing Apache blog virtualhost
5
-  command: mv /etc/apache2/sites-available/{{ domain }} /etc/apache2/sites-available/{{ domain }}.conf removes=/etc/apache2/sites-available/{{ domain }}
5
+- name: Create the Apache sites config file
6
+  template:
7
+    src=etc_apache2_sites-available_blog.j2
8
+    dest=/etc/apache2/sites-available/{{ item.name }}.conf
9
+    owner=root
10
+    group=root
11
+  with_items: "{{ virtual_domains }}"
6 12
 
7
-- name: Remove old sites-enabled/{{ domain }} symlink (new one will be created by a2ensite)
8
-  file: path=/etc/apache2/sites-enabled/{{ domain }} state=absent
13
+- name: Remove old sites-enabled symlinks (new ones will be created by a2ensite)
14
+  file: path=/etc/apache2/sites-enabled/{{ item }}.conf state=absent
15
+  with_items: "{{ virtual_domains | json_query('[*].name') }}"
9 16
 
10
-- name: Configure the Apache HTTP server for the blog
11
-  template: src=etc_apache2_sites-available_blog.j2 dest=/etc/apache2/sites-available/{{ domain }}.conf group=root owner=root
12
-
13
-- name: Enable blog site
14
-  command: a2ensite {{ domain }}.conf creates=/etc/apache2/sites-enabled/{{ domain }}.conf
17
+- name: Enable Apache sites (creates new sites-enabled symlinks)
18
+  command: a2ensite {{ item }}.conf creates=/etc/apache2/sites-enabled/{{ item }}.conf
15 19
   notify: restart apache
16
-
20
+  with_items: "{{ virtual_domains | json_query('[*].name') }}"

+ 7
- 9
roles/blog/templates/etc_apache2_sites-available_blog.j2 View File

@@ -1,19 +1,17 @@
1 1
 <VirtualHost *:80>
2
-    ServerName {{ domain }}
3
-    ServerAlias www.{{ domain }}
2
+    ServerName {{ item.name }}
3
+    ServerAlias www.{{ item.name }}
4 4
 
5
-    Redirect permanent / https://{{ domain }}/
5
+    Redirect permanent / https://{{ item.name }}/
6 6
 </VirtualHost>
7 7
 
8
-
9 8
 <VirtualHost *:443>
10
-    ServerName {{ domain }}
11
-    ServerAlias www.{{ domain }}
12
-    SSLEngine On
9
+    ServerName {{ item.name }}
10
+    ServerAlias www.{{ item.name }}
13 11
 
14
-    DocumentRoot            "/var/www/{{ domain }}"
12
+    SSLEngine               On
13
+    DocumentRoot            "{{ item.doc_root }}"
15 14
     DirectoryIndex          index.html
16 15
     Options                 -Indexes
17
-
18 16
     HostnameLookups         Off
19 17
 </VirtualHost>

Loading…
Cancel
Save