Browse Source

Major vhosts cleanup in preparation for issue #11.

Jeff Geerling 10 years ago
parent
commit
7360d9cb0b
7 changed files with 35 additions and 9 deletions
  1. 5 2
      README.md
  2. 2 1
      defaults/main.yml
  3. 1 6
      tasks/main.yml
  4. 22 0
      tasks/vhosts.yml
  5. 1 0
      templates/vhosts.j2
  6. 2 0
      vars/Debian.yml
  7. 2 0
      vars/RedHat.yml

+ 5 - 2
README.md

@@ -14,10 +14,13 @@ None.
 
 Available variables are listed below, along with default values (see `defaults/main.yml`):
 
+    nginx_vhost_path: /etc/nginx/sites-enabled
+
+The path to the vhost configuration folder (where Nginx will look for server configurations).
+
     nginx_remove_default_vhost: false
-    nginx_default_vhost_path: /etc/nginx/sites-enabled/default
 
-Whether to remove the 'default' virtualhost configuration supplied by Nginx. Useful if you want the base `/` URL to be directed at one of your own virtual hosts configured in a separate .conf file. The `nginx_default_vhost_path` variable defines the path to the default vhosts file.
+Whether to remove the 'default' virtualhost configuration supplied by Nginx. Useful if you want the base `/` URL to be directed at one of your own virtual hosts configured in a separate .conf file.
 
     nginx_user: "nginx"
 

+ 2 - 1
defaults/main.yml

@@ -5,6 +5,7 @@ nginx_client_max_body_size: "64m"
 nginx_keepalive_timeout: "65"
 
 nginx_remove_default_vhost: false
-nginx_default_vhost_path: /etc/nginx/sites-enabled/default
+nginx_vhosts: []
+# TODO - add example.
 
 nginx_proxy_cache_path: ""

+ 1 - 6
tasks/main.yml

@@ -28,9 +28,4 @@
 - name: Ensure nginx is started and enabled to start at boot.
   service: name=nginx state=started enabled=yes
 
-- name: Remove default nginx config file (if configured).
-  file:
-    path: "{{ nginx_default_vhost_path }}"
-    state: absent
-  when: nginx_remove_default_vhost
-  notify: restart nginx
+- include: vhosts.yml

+ 22 - 0
tasks/vhosts.yml

@@ -0,0 +1,22 @@
+---
+- name: Remove default nginx vhost config file (if configured).
+  file:
+    path: "{{ nginx_default_vhost_path }}"
+    state: absent
+  when: nginx_remove_default_vhost
+  notify: restart nginx
+
+- name: Add managed vhost config file (if any vhosts are configured).
+  template:
+    src: vhosts.j2
+    dest: "{{ nginx_vhost_path }}/vhosts"
+    mode: 0644
+  when: nginx_vhosts
+  notify: restart nginx
+
+- name: Remove managed vhost config file (if no vhosts are configured).
+  file:
+    path: "{{ nginx_vhost_path }}/vhosts"
+    state: absent
+  when: not nginx_vhosts
+  notify: restart nginx

+ 1 - 0
templates/vhosts.j2

@@ -0,0 +1 @@
+# TODO

+ 2 - 0
vars/Debian.yml

@@ -1,2 +1,4 @@
 ---
+nginx_vhost_path: /etc/nginx/sites-enabled
+nginx_default_vhost_path: /etc/nginx/sites-enabled/default
 __nginx_user: "www-data"

+ 2 - 0
vars/RedHat.yml

@@ -1,2 +1,4 @@
 ---
+nginx_vhost_path: /etc/nginx/conf.d
+nginx_default_vhost_path: /etc/nginx/conf.d/default.conf
 __nginx_user: "nginx"