diff --git a/varnish/defaults/main.yml b/varnish/defaults/main.yml index fe7e986b..8670c1d2 100644 --- a/varnish/defaults/main.yml +++ b/varnish/defaults/main.yml @@ -1,2 +1,3 @@ --- thread_pools: "{{ ansible_processor_cores * ansible_processor_count }}" +malloc: "2G" diff --git a/varnish/files/reload-vcl.sh b/varnish/files/reload-vcl.sh new file mode 100644 index 00000000..537dcddf --- /dev/null +++ b/varnish/files/reload-vcl.sh @@ -0,0 +1,5 @@ +#!/bin/sh +UUID=`cat /proc/sys/kernel/random/uuid` +/usr/sbin/varnishd -C -f /etc/varnish/default.vcl >/dev/null \ + &&/usr/bin/varnishadm -T localhost:6082 -S /etc/varnish/secret "vcl.load vcl_$UUID /etc/varnish/default.vcl" \ + && /usr/bin/varnishadm -T localhost:6082 -S /etc/varnish/secret "vcl.use vcl_$UUID" diff --git a/varnish/tasks/main.yml b/varnish/tasks/main.yml index a2a17baf..d9f1fa3e 100644 --- a/varnish/tasks/main.yml +++ b/varnish/tasks/main.yml @@ -12,11 +12,27 @@ copy: src: "/lib/systemd/system/varnish.service" dest: "/etc/systemd/system/" + remote_src: True force: no + mode: 0644 + owner: root + group: root -- name: Modify Varnish configuration file - lineinfile: +- name: Copy Custom Varnish ExecReload script + copy: + src: "reload-vcl.sh" + dest: "/etc/varnish/reload-vcl.sh" + mode: 0700 + owner: root + group: root + +- name: Modify Varnish configuration files + ini_file: dest: "/etc/systemd/system/varnish.service" - regexp: "^ExecStart=" - line: "ExecStart=/usr/sbin/varnishd -a 0.0.0.0:80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,2G -p thread_pools={{ thread_pools }} -p thread_pool_add_delay=2 -p thread_pool_min=500 -p thread_pool_max=5000" + section: "Service" + option: "{{ item.option }}" + value: "{{ value.value }}" notify: reload systemctl + with_items: + - { option: 'ExecStart', value: '/usr/sbin/varnishd -a 0.0.0.0:80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,{{ malloc }} -p thread_pools={{ thread_pools }} -p thread_pool_add_delay=2 -p thread_pool_min=500 -p thread_pool_max=5000' } + - { option: 'ExecReload', value: '/etc/varnish/reload-vcl.sh' }