diff --git a/README.md b/README.md index 6d46b94..2e4a2d6 100644 --- a/README.md +++ b/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 diff --git a/defaults/main.yml b/defaults/main.yml index 68d60c1..5161e82 100644 --- a/defaults/main.yml +++ b/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: [] diff --git a/tasks/vhosts.yml b/tasks/vhosts.yml index e6dd5f6..03c32d9 100644 --- a/tasks/vhosts.yml +++ b/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