---
# Tasks to set up varnish

- name: install needed packages
  package: name={{ item }} state=present
  with_items:
  - libsemanage-python
  - varnish
  tags:
  - varnish
  - packages

- name: set some varnishd selinux boolean
  seboolean: name=varnishd_connect_any persistent=yes state=yes
  tags:
  - varnish
  - selinux

- name: install varnish /etc/sysconfig/varnish file (el7)
  copy: src=varnish.el7 dest=/etc/sysconfig/varnish owner=root group=root
  notify:
  - restart varnish
  tags:
  - varnish
  when: ansible_distribution_major_version|int == 7

- name: install varnish /etc/sysconfig/varnish file (fedora 25-28)
  template: src=varnish.f25.j2 dest=/etc/varnish/varnish.params owner=root group=root
  notify:
  - restart varnish
  tags:
  - varnish
  when: ansible_distribution_major_version|int >= 25 and ansible_distribution_major_version|int < 29

- name: install varnish /etc/systemd/system/varnish.service file (fedora 29+)
  template: src=varnish.f29.j2 dest=/etc/systemd/system/varnish.service owner=root group=root
  notify:
  - reload systemd
  - restart varnish
  tags:
  - varnish
  when: ansible_distribution_major_version|int >= 29

- name: install /etc/varnish/default.vcl (proxies)
  template: src={{ varnish_group }}.vcl.j2 dest=/etc/varnish/default.vcl owner=root group=root
  notify:
  - restart varnish
  tags:
  - varnish

- name: make sure varnish is set to enabled on boot
  service: enabled=yes name=varnish
  tags:
  - varnish
