ansible-roles/varnish/tasks/main.yml

193 lines
4.4 KiB
YAML
Raw Normal View History

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
- name: Fetch packages
package_facts:
manager: auto
check_mode: no
tags:
- varnish
- config
- update-config
- set_fact:
varnish_package_facts: "{{ ansible_facts.packages['varnish'] | first }}"
check_mode: no
tags:
- varnish
- config
- update-config
# - debug:
# var: varnish_package_facts
# check_mode: no
# tags:
# - varnish
# - config
# - update-config
2016-11-15 20:00:26 +01:00
- name: Remove default varnish configuration files
file:
path: "{{ item }}"
state: absent
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
- name: Copy Custom Varnish ExecReload script (Debian < 10)
template:
src: "reload-vcl.sh.j2"
dest: "/etc/varnish/reload-vcl.sh"
mode: "0700"
owner: root
group: root
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 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:
path: /etc/systemd/system/varnish.service.d/evolinux.conf
state: absent
notify:
- reload systemd
tags:
- varnish
2022-11-02 22:30:09 +01:00
- config
- 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
- 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
- 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
- name: Override Varnish systemd unit
template:
src: "{{ varnish_systemd_override_template }}"
dest: /etc/systemd/system/varnish.service.d/override.conf
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 }}"
dest: "{{ varnish_config_file }}"
2017-05-15 14:21:28 +02:00
mode: "0644"
2017-05-12 12:40:23 +02:00
force: yes
loop: "{{ query('first_found', templates) }}"
vars:
templates:
- "templates/varnish/varnish.{{ inventory_hostname }}.vcl.j2"
- "templates/varnish/default.{{ inventory_hostname }}.vcl.j2"
- "templates/varnish/varnish.{{ host_group | default('all') }}.vcl.j2"
- "templates/varnish/default.{{ host_group | default('all') }}.vcl.j2"
- "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
# 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