--- - name: Install Varnish apt: name: varnish state: present tags: - varnish - 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 - name: Remove default varnish configuration files file: path: "{{ item }}" state: absent loop: - /etc/default/varnish - /etc/default/varnishncsa - /etc/default/varnishlog notify: reload varnish tags: - varnish - config - 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', '<') notify: reload varnish tags: - varnish - name: Create a system config directory for systemd overrides file: path: /etc/systemd/system/varnish.service.d state: directory tags: - varnish - config - name: Remove legacy systemd override file: path: /etc/systemd/system/varnish.service.d/evolinux.conf state: absent notify: - reload systemd tags: - varnish - 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', '<') 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', '<') 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', '>=') 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 notify: - reload systemd - restart varnish tags: - varnish - config - update-config - name: Patch logrotate conf replace: name: /etc/logrotate.d/varnish regexp: '^(\s+)(/usr/sbin/invoke-rc.d {{item}}.*)' replace: '\1systemctl -q is-active {{item}} && \2' loop: - varnishlog - varnishncsa tags: - varnish - logrotate - name: Copy Varnish configuration template: src: "{{ item }}" dest: "{{ varnish_config_file }}" mode: "0644" 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" notify: reload varnish tags: - varnish - config - update-config - name: Create Varnish config dir file: path: /etc/varnish/conf.d state: directory mode: "0755" tags: - varnish - config - update-config - name: Copy included Varnish config template: src: "{{ item }}" dest: /etc/varnish/conf.d/ force: yes mode: "0644" with_fileglob: - "templates/varnish/conf.d/*.vcl" notify: reload varnish tags: - varnish - config - update-config # 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" - include: munin.yml