浏览代码

Issue #95: Add support for setting template on a per vhost basis

Oskar Schöldström 8 年之前
父节点
当前提交
5e41c6b1f9
共有 3 个文件被更改,包括 18 次插入1 次删除
  1. 16 0
      README.md
  2. 1 0
      defaults/main.yml
  3. 1 1
      tasks/vhosts.yml

+ 16 - 0
README.md

@@ -27,6 +27,7 @@ A list of vhost definitions (server blocks) for Nginx virtual hosts. Each entry
         access_log: ""
         error_log: ""
         state: "present"
+        template: "{{ nginx_vhost_template }}"
         extra_parameters: |
           location ~ \.php$ {
               fastcgi_split_path_info ^(.+\.php)(/.+)$;
@@ -130,6 +131,21 @@ nginx_conf_template: "nginx.conf.j2"
 nginx_vhost_template: "vhost.j2"
 ```
 
+If necessary you can also set the template on a per vhost basis.
+
+```yaml
+nginx_vhosts:
+  - listen: "80 default_server"
+    server_name: "site1.example.com"
+    root: "/var/www/site1.example.com"
+    index: "index.php index.html index.htm"
+    template: "{{ playbook_dir }}/templates/site1.example.com.vhost.j2"
+  - server_name: "site2.example.com"
+    root: "/var/www/site2.example.com"
+    index: "index.php index.html index.htm"
+    template: "{{ playbook_dir }}/templates/site2.example.com.vhost.j2"
+```
+
 You can either copy and modify the provided template, or extend it with [Jinja2 template inheritance](http://jinja.pocoo.org/docs/2.9/templates/#template-inheritance) and override the specific template block you need to change.
 
 ### Example: Configure gzip in nginx configuration

+ 1 - 0
defaults/main.yml

@@ -65,6 +65,7 @@ nginx_vhosts: []
 #   access_log: ""
 #   error_log: ""
 #   extra_parameters: "" # Can be used to add extra config blocks (multiline).
+#   template: "" # Can be used to override the `nginx_vhost_template` per host.
 #   state: "absent" # To remove the vhost configuration.
 
 nginx_upstreams: []

+ 1 - 1
tasks/vhosts.yml

@@ -14,7 +14,7 @@
 
 - name: Add managed vhost config files.
   template:
-    src: "{{ nginx_vhost_template }}"
+    src: "{{ item.template|default(nginx_vhost_template) }}"
     dest: "{{ nginx_vhost_path }}/{{ item.server_name.split(' ')[0] }}.conf"
     force: yes
     owner: root