From 98081e863591d4f43447184fa69acc9f43d9ba63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Robin=20Ob=C5=AFrka?= <robin.oburka@nic.cz>
Date: Tue, 18 Oct 2016 14:58:26 +0200
Subject: nginx: Provide new mechanism for default page manipulation

Important changes:
- The well-known path is moved to the separate snippet acme.conf
- It is possible to disable default page
- The autodetection mechanism for default page is provided
---
 roles/nginx/tasks/main.yml | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

(limited to 'roles/nginx/tasks')

diff --git a/roles/nginx/tasks/main.yml b/roles/nginx/tasks/main.yml
index 2ac852e..4d4b085 100644
--- a/roles/nginx/tasks/main.yml
+++ b/roles/nginx/tasks/main.yml
@@ -51,6 +51,7 @@
     group: root
     mode: 0644
   with_items:
+  - acme.conf
   - common.conf
   - ssl-common.conf
   - ssl-medium-common.conf
@@ -70,18 +71,27 @@
   - restart nginx
   when: stat_default.stat.exists and stat_default.stat.islnk == True
 
-- name: Deploy temporary default page (with our snippets etc)
+- name: Detect acme configuration on some vhost
+  shell: ls | grep -v default | while read LINE; do cat "$LINE" ; done | grep -q 'include snippets/acme.conf'
+  args:
+    chdir: /etc/nginx/sites-enabled
+  register: autodetect
+  changed_when: False
+  failed_when: False
+  when: nginx_deploy_default_config == True and nginx_enable_autodetection == True
+
+- name: Deploy default page (with our snippets etc)
   copy:
     src: default
     ## Do not deploy it as symlik
-    ## This method keeps default config available, provides necessary definitions (.well-known)
-    ## and the particular server ussually deletes /etc/nginx/sites-enabled/default
     dest: /etc/nginx/sites-enabled/default
     owner: root
     group: root
     mode: 0644
   notify:
   - restart nginx
+  when: (nginx_deploy_default_config == True and nginx_enable_autodetection == True and autodetect.rc != 0) or
+        (nginx_deploy_default_config == True and nginx_enable_autodetection == False)
 
 - meta: flush_handlers
 
-- 
cgit v1.2.3