Skip to content

Commit 615e020

Browse files
authored
Reworking-varnish-role (#2354)
* Reworking-varnish-role * Reworking-varnish-role-PR-2.x * Updating-varnish-pid-var * Reworking-varnish-role-config-PR-2.x
1 parent d477c60 commit 615e020

File tree

3 files changed

+58
-14
lines changed

3 files changed

+58
-14
lines changed

roles/debian/varnish_config/defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
---
22
# Defaults file for varnish_config, other variables exist from importing geerlingguy.varnish and can be overriden
33

4+
limit_memlock: 82000
5+
limit_core: infinity
6+
tasks_max: infinity
7+
varnish_storage: "malloc,{{ ansible_facts.memtotal_mb // 10 }}M"
48
varnish_config:
59
# List of IPs that are allowed to ask for content purge.
610
allowed_purge_IP: []
@@ -17,3 +21,4 @@ varnish_config:
1721
upstream_proxies: []
1822
# Provide an alternative filename if you are providing a template.
1923
template_filename: default.vcl
24+
# Varnish systemd overrides to make varnish consistent even after upgrades
Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
---
2-
- name: Copy Varnish default VCL.
3-
ansible.builtin.template:
4-
src: "{{ item }}"
5-
dest: "{{ varnish_config_path }}/default.vcl"
6-
owner: root
7-
group: root
8-
mode: 0644
9-
with_first_found:
10-
- "{{ playbook_dir }}/templates/{{ varnish_config.template_filename }}.j2"
11-
- "{{ _ce_provision_base_dir }}/config/files/templates/{{ varnish_config.template_filename }}.j2"
12-
- "default.vcl.j2"
13-
notify:
14-
- reload systemd # handlers in https://github.com/geerlingguy/ansible-role-varnish/blob/master/handlers/main.yml
15-
- restart varnish
2+
- block:
3+
- name: Copy Varnish default VCL.
4+
ansible.builtin.template:
5+
src: "{{ item }}"
6+
dest: "{{ varnish_config_path }}/default.vcl"
7+
owner: root
8+
group: root
9+
mode: 0644
10+
with_first_found:
11+
- "{{ playbook_dir }}/templates/{{ varnish_config.template_filename }}.j2"
12+
- "{{ _ce_provision_base_dir }}/config/files/templates/{{ varnish_config.template_filename }}.j2"
13+
- "default.vcl.j2"
14+
# This will keep varnish config as it is even after varnish upgrade
15+
- name: Template varnish systemd service file
16+
ansible.builtin.template:
17+
src: varnish.service.j2
18+
dest: /etc/systemd/system/varnish.service
19+
mode: '0644'
20+
notify:
21+
- reload systemd
22+
- restart varnish
23+
24+
# TO DO: add varnish to unattended upgrades
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[Unit]
2+
Description=Varnish Cache, a high-performance HTTP accelerator
3+
After=network-online.target
4+
5+
[Service]
6+
Type=forking
7+
KillMode=process
8+
9+
PIDFile= {{ varnish_pidfile }}
10+
11+
# Maximum number of open files (for ulimit -n)
12+
LimitNOFILE= {{ varnish_limit_nofile }}
13+
14+
# Locked shared memory
15+
LimitMEMLOCK= {{ limit_memlock }}
16+
17+
# Enable this to avoid "fork failed" on reload.
18+
TasksMax= {{ tasks_max }}
19+
20+
# Maximum size of the corefile.
21+
LimitCORE= {{ limit_core }}
22+
23+
ExecStart=/usr/sbin/varnishd -a :80 -T 127.0.0.1:6082 -P /run/varnishd.pid -f /etc/varnish/default.vcl -S /etc/varnish/secret -s {{ varnish_storage }}
24+
25+
ExecReload=/usr/sbin/varnishreload
26+
27+
Restart=on-failure
28+
29+
[Install]
30+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)