Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworking-varnish-role #2354

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions roles/debian/varnish_config/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
---
# Defaults file for varnish_config, other variables exist from importing geerlingguy.varnish and can be overriden

varnish_pid: /run/varnishd.pid
limit_nofile: 131072
limit_memlock: 82000
limit_core: infinity
tasks_max: infinity
varnish_storage: "malloc,{{ ansible_facts.memtotal_mb // 10 }}M"
varnish_config:
# List of IPs that are allowed to ask for content purge.
allowed_purge_IP: []
Expand All @@ -17,3 +23,4 @@ varnish_config:
upstream_proxies: []
# Provide an alternative filename if you are providing a template.
template_filename: default.vcl
# Varnish systemd overrides to make varnish consistent even after upgrades
37 changes: 23 additions & 14 deletions roles/debian/varnish_config/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
---
- name: Copy Varnish default VCL.
ansible.builtin.template:
src: "{{ item }}"
dest: "{{ varnish_config_path }}/default.vcl"
owner: root
group: root
mode: 0644
with_first_found:
- "{{ playbook_dir }}/templates/{{ varnish_config.template_filename }}.j2"
- "{{ _ce_provision_base_dir }}/config/files/templates/{{ varnish_config.template_filename }}.j2"
- "default.vcl.j2"
notify:
- reload systemd # handlers in https://github.com/geerlingguy/ansible-role-varnish/blob/master/handlers/main.yml
- restart varnish
- block:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why we need this block? please add a code comment.

- name: Copy Varnish default VCL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation should be 2 spaces, or is there a reason here are 4?

ansible.builtin.template:
src: "{{ item }}"
dest: "{{ varnish_config_path }}/default.vcl"
owner: root
group: root
mode: 0644
with_first_found:
- "{{ playbook_dir }}/templates/{{ varnish_config.template_filename }}.j2"
- "{{ _ce_provision_base_dir }}/config/files/templates/{{ varnish_config.template_filename }}.j2"
- "default.vcl.j2"
# This will keep varnish config as it is even after varnish upgrade
- name: Template varnish systemd service file
ansible.builtin.template:
src: varnish.service.j2
dest: /etc/systemd/system/varnish.service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is also a systemd file in /lib/systemd/system/varnish.service , probably installed by the varnish package. Do we need to take care of that?

mode: '0644'
notify:
- reload systemd
- restart varnish

# TO DO: add varnish to unattended upgrades
30 changes: 30 additions & 0 deletions roles/debian/varnish_config/templates/varnish.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[Unit]
Description=Varnish Cache, a high-performance HTTP accelerator
After=network-online.target

[Service]
Type=forking
KillMode=process

PIDFile= {{ varnish_pid }}

# Maximum number of open files (for ulimit -n)
LimitNOFILE= {{ limit_nofile }}

# Locked shared memory
LimitMEMLOCK= {{ limit_memlock }}

# Enable this to avoid "fork failed" on reload.
TasksMax= {{ tasks_max }}

# Maximum size of the corefile.
LimitCORE= {{ limit_core }}

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 }}

ExecReload=/usr/sbin/varnishreload

Restart=on-failure

[Install]
WantedBy=multi-user.target
Loading