diff --git a/varnish/handlers/main.yml b/varnish/handlers/main.yml index 1bed9bee..6740061b 100644 --- a/varnish/handlers/main.yml +++ b/varnish/handlers/main.yml @@ -1,3 +1,9 @@ --- - name: reload systemctl - command: systemctl daemon-reload + systemd: + daemon_reload: yes + +- name: reload varnish + service: + name: varnish + state: reloaded diff --git a/varnish/tasks/main.yml b/varnish/tasks/main.yml index 0f94b1e8..4cbda0a3 100644 --- a/varnish/tasks/main.yml +++ b/varnish/tasks/main.yml @@ -39,3 +39,15 @@ with_items: - varnishlog - varnishncsa + +- name: Copy Varnish configuration + template: + src: "{{ item }}" + dest: /etc/varnish/default.vcl + force: yes + with_first_found: + - "templates/varnish/default.{{ inventory_hostname }}.vcl.j2" + - "templates/varnish/default.{{ host_group }}.vcl.j2" + - "templates/varnish/default.default.vcl.j2" + - "default.vcl.j2" + notify: reload varnish diff --git a/varnish/templates/default.vcl.j2 b/varnish/templates/default.vcl.j2 new file mode 100644 index 00000000..d2d6c149 --- /dev/null +++ b/varnish/templates/default.vcl.j2 @@ -0,0 +1,41 @@ +# +# This is an example VCL file for Varnish. +# +# It does not do anything by default, delegating control to the +# builtin VCL. The builtin VCL is called when there is no explicit +# return statement. +# +# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/ +# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples. + +# Marker to tell the VCL compiler that this VCL has been adapted to the +# new 4.0 format. +vcl 4.0; + +# Default backend definition. Set this to point to your content server. +backend default { + .host = "127.0.0.1"; + .port = "8080"; +} + +sub vcl_recv { + # Happens before we check if we have this in cache already. + # + # Typically you clean up the request here, removing cookies you don't need, + # rewriting the request, etc. +} + +sub vcl_backend_response { + # Happens after we have read the response headers from the backend. + # + # Here you clean the response headers, removing silly Set-Cookie headers + # and other mistakes your backend does. +} + +sub vcl_deliver { + # Happens when we have all the pieces we need, and are about to send the + # response to the client. + # + # You can do accounting or modifying the final object here. +} +