2016-11-15 20:00:26 +01:00
|
|
|
---
|
|
|
|
- name: Install Varnish
|
2016-11-18 16:24:54 +01:00
|
|
|
apt:
|
|
|
|
name: varnish
|
|
|
|
state: present
|
2017-05-12 13:44:59 +02:00
|
|
|
tags:
|
2020-12-20 23:00:50 +01:00
|
|
|
- varnish
|
2016-11-15 20:00:26 +01:00
|
|
|
|
2022-11-02 13:29:58 +01:00
|
|
|
- name: Fetch packages
|
|
|
|
package_facts:
|
|
|
|
manager: auto
|
2022-11-21 15:46:46 +01:00
|
|
|
check_mode: no
|
2022-11-02 13:29:58 +01:00
|
|
|
tags:
|
|
|
|
- varnish
|
2022-11-21 15:46:46 +01:00
|
|
|
- config
|
|
|
|
- update-config
|
2022-11-02 13:29:58 +01:00
|
|
|
|
|
|
|
- set_fact:
|
2022-11-21 15:46:46 +01:00
|
|
|
varnish_package_facts: "{{ ansible_facts.packages['varnish'] | first }}"
|
|
|
|
check_mode: no
|
2022-11-02 13:29:58 +01:00
|
|
|
tags:
|
|
|
|
- varnish
|
2022-11-21 15:46:46 +01:00
|
|
|
- config
|
|
|
|
- update-config
|
|
|
|
|
|
|
|
# - debug:
|
|
|
|
# var: varnish_package_facts
|
|
|
|
# check_mode: no
|
|
|
|
# tags:
|
|
|
|
# - varnish
|
|
|
|
# - config
|
|
|
|
# - update-config
|
2022-11-02 13:29:58 +01:00
|
|
|
|
2016-11-15 20:00:26 +01:00
|
|
|
- name: Remove default varnish configuration files
|
|
|
|
file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
state: absent
|
2021-05-04 14:18:40 +02:00
|
|
|
loop:
|
2020-12-20 23:00:50 +01:00
|
|
|
- /etc/default/varnish
|
|
|
|
- /etc/default/varnishncsa
|
|
|
|
- /etc/default/varnishlog
|
2017-11-30 23:51:18 +01:00
|
|
|
notify: reload varnish
|
2017-05-12 13:44:59 +02:00
|
|
|
tags:
|
2020-12-20 23:00:50 +01:00
|
|
|
- varnish
|
2020-12-23 15:43:05 +01:00
|
|
|
- config
|
2016-11-15 20:00:26 +01:00
|
|
|
|
2022-11-02 13:29:58 +01:00
|
|
|
- name: Copy Custom Varnish ExecReload script (Debian < 10)
|
2020-12-20 22:55:39 +01:00
|
|
|
template:
|
|
|
|
src: "reload-vcl.sh.j2"
|
2016-11-18 15:51:44 +01:00
|
|
|
dest: "/etc/varnish/reload-vcl.sh"
|
2017-03-23 16:59:43 +01:00
|
|
|
mode: "0700"
|
2016-11-18 15:51:44 +01:00
|
|
|
owner: root
|
|
|
|
group: root
|
2020-12-20 23:25:34 +01:00
|
|
|
when: ansible_distribution_major_version is version('10', '<')
|
2017-11-30 23:51:18 +01:00
|
|
|
notify: reload varnish
|
2017-05-12 13:44:59 +02:00
|
|
|
tags:
|
2020-12-20 23:00:50 +01:00
|
|
|
- varnish
|
2016-11-18 15:51:44 +01:00
|
|
|
|
2016-11-18 16:24:54 +01:00
|
|
|
- name: Create a system config directory for systemd overrides
|
|
|
|
file:
|
|
|
|
path: /etc/systemd/system/varnish.service.d
|
|
|
|
state: directory
|
2017-05-12 13:44:59 +02:00
|
|
|
tags:
|
2020-12-20 23:00:50 +01:00
|
|
|
- varnish
|
2022-11-02 22:30:09 +01:00
|
|
|
- config
|
2016-11-18 16:24:54 +01:00
|
|
|
|
2022-11-02 22:30:09 +01:00
|
|
|
- name: Remove legacy systemd override
|
|
|
|
file:
|
2022-11-26 19:10:21 +01:00
|
|
|
path: /etc/systemd/system/varnish.service.d/evolinux.conf
|
|
|
|
state: absent
|
2020-12-20 23:25:34 +01:00
|
|
|
notify:
|
|
|
|
- reload systemd
|
|
|
|
tags:
|
|
|
|
- varnish
|
2022-11-02 22:30:09 +01:00
|
|
|
- config
|
2020-12-20 23:25:34 +01:00
|
|
|
|
2022-11-02 13:29:58 +01:00
|
|
|
- name: Varnish systemd override template (Varnish 4 and 5)
|
|
|
|
set_fact:
|
|
|
|
varnish_systemd_override_template: override.conf.varnish4.j2
|
|
|
|
when:
|
|
|
|
- varnish_package_facts['version'] is version('4', '>=')
|
|
|
|
- varnish_package_facts['version'] is version('6', '<')
|
2022-11-02 22:30:09 +01:00
|
|
|
tags:
|
|
|
|
- varnish
|
|
|
|
- config
|
|
|
|
- update-config
|
2022-11-02 13:29:58 +01:00
|
|
|
|
|
|
|
- name: Varnish systemd override template (Varnish 6)
|
|
|
|
set_fact:
|
|
|
|
varnish_systemd_override_template: override.conf.varnish6.j2
|
|
|
|
when:
|
|
|
|
- varnish_package_facts['version'] is version('6', '>=')
|
|
|
|
- varnish_package_facts['version'] is version('7', '<')
|
2022-11-02 22:30:09 +01:00
|
|
|
tags:
|
|
|
|
- varnish
|
|
|
|
- config
|
|
|
|
- update-config
|
2022-11-02 13:29:58 +01:00
|
|
|
|
|
|
|
- name: Varnish systemd override template (Varnish 7 and later)
|
|
|
|
set_fact:
|
|
|
|
varnish_systemd_override_template: override.conf.varnish7.j2
|
|
|
|
when:
|
|
|
|
- varnish_package_facts['version'] is version('7', '>=')
|
2022-11-02 22:30:09 +01:00
|
|
|
tags:
|
|
|
|
- varnish
|
|
|
|
- config
|
|
|
|
- update-config
|
2022-11-02 13:29:58 +01:00
|
|
|
|
|
|
|
- name: Override Varnish systemd unit
|
2020-12-20 23:25:34 +01:00
|
|
|
template:
|
2022-11-02 13:29:58 +01:00
|
|
|
src: "{{ varnish_systemd_override_template }}"
|
|
|
|
dest: /etc/systemd/system/varnish.service.d/override.conf
|
2020-12-20 23:25:34 +01:00
|
|
|
force: yes
|
2017-11-30 23:51:18 +01:00
|
|
|
notify:
|
|
|
|
- reload systemd
|
|
|
|
- restart varnish
|
2017-05-12 13:44:59 +02:00
|
|
|
tags:
|
2020-12-20 23:00:50 +01:00
|
|
|
- varnish
|
2020-12-23 15:43:05 +01:00
|
|
|
- config
|
|
|
|
- update-config
|
2017-03-30 17:54:58 +02:00
|
|
|
|
|
|
|
- name: Patch logrotate conf
|
|
|
|
replace:
|
|
|
|
name: /etc/logrotate.d/varnish
|
2022-12-28 09:03:37 +01:00
|
|
|
regexp: '^(\s+)(/usr/sbin/invoke-rc.d {{ item }}.*)'
|
|
|
|
replace: '\1systemctl -q is-active {{ item }} && \2'
|
2020-12-23 15:43:05 +01:00
|
|
|
loop:
|
2017-03-30 17:54:58 +02:00
|
|
|
- varnishlog
|
|
|
|
- varnishncsa
|
2017-05-12 13:44:59 +02:00
|
|
|
tags:
|
2020-12-20 23:00:50 +01:00
|
|
|
- varnish
|
2020-12-23 15:43:05 +01:00
|
|
|
- logrotate
|
2017-05-12 12:40:23 +02:00
|
|
|
|
|
|
|
- name: Copy Varnish configuration
|
|
|
|
template:
|
|
|
|
src: "{{ item }}"
|
2020-12-20 22:55:39 +01:00
|
|
|
dest: "{{ varnish_config_file }}"
|
2017-05-15 14:21:28 +02:00
|
|
|
mode: "0644"
|
2017-05-12 12:40:23 +02:00
|
|
|
force: yes
|
2021-05-04 13:39:47 +02:00
|
|
|
loop: "{{ query('first_found', templates) }}"
|
|
|
|
vars:
|
|
|
|
templates:
|
|
|
|
- "templates/varnish/varnish.{{ inventory_hostname }}.vcl.j2"
|
|
|
|
- "templates/varnish/default.{{ inventory_hostname }}.vcl.j2"
|
2021-05-19 14:35:08 +02:00
|
|
|
- "templates/varnish/varnish.{{ host_group | default('all') }}.vcl.j2"
|
|
|
|
- "templates/varnish/default.{{ host_group | default('all') }}.vcl.j2"
|
2021-05-04 13:39:47 +02:00
|
|
|
- "templates/varnish/varnish.default.vcl.j2"
|
|
|
|
- "templates/varnish/default.default.vcl.j2"
|
|
|
|
- "templates/varnish.vcl.j2"
|
|
|
|
- "templates/default.vcl.j2"
|
2017-05-12 12:40:23 +02:00
|
|
|
notify: reload varnish
|
2017-05-12 13:44:59 +02:00
|
|
|
tags:
|
2020-12-20 23:00:50 +01:00
|
|
|
- varnish
|
2020-12-23 15:43:05 +01:00
|
|
|
- config
|
|
|
|
- update-config
|
2017-05-15 14:21:28 +02:00
|
|
|
|
|
|
|
- name: Create Varnish config dir
|
|
|
|
file:
|
|
|
|
path: /etc/varnish/conf.d
|
|
|
|
state: directory
|
|
|
|
mode: "0755"
|
|
|
|
tags:
|
2020-12-20 23:00:50 +01:00
|
|
|
- varnish
|
2020-12-23 15:43:05 +01:00
|
|
|
- config
|
2021-05-06 13:03:12 +02:00
|
|
|
- update-config
|
2017-05-15 14:21:28 +02:00
|
|
|
|
|
|
|
- name: Copy included Varnish config
|
|
|
|
template:
|
|
|
|
src: "{{ item }}"
|
|
|
|
dest: /etc/varnish/conf.d/
|
|
|
|
force: yes
|
|
|
|
mode: "0644"
|
|
|
|
with_fileglob:
|
2020-12-23 15:43:05 +01:00
|
|
|
- "templates/varnish/conf.d/*.vcl"
|
2017-05-15 14:21:28 +02:00
|
|
|
notify: reload varnish
|
|
|
|
tags:
|
2020-12-20 23:00:50 +01:00
|
|
|
- varnish
|
2020-12-23 15:43:05 +01:00
|
|
|
- config
|
|
|
|
- update-config
|
2017-05-23 22:19:29 +02:00
|
|
|
|
2022-11-02 19:45:15 +01:00
|
|
|
# To validate the configuration, we must use a tmp directory that is mounted as exec
|
|
|
|
# We usually use /vat/tmp-cache then validate the syntax with this command:
|
|
|
|
# sudo -u vcache TMPDIR=/var/tmp-vcache varnishd -Cf /etc/varnish/default.vcl > /dev/null
|
|
|
|
- name: Special tmp directory
|
|
|
|
file:
|
|
|
|
path: "{{ varnish_tmp_dir }}"
|
|
|
|
state: directory
|
|
|
|
owner: vcache
|
|
|
|
group: varnish
|
|
|
|
mode: "0750"
|
|
|
|
|
2017-05-23 22:19:29 +02:00
|
|
|
- include: munin.yml
|