---
- name: Install packages needed
  ansible.builtin.package: name={{ item }} state=present
  with_items:
  - squid
  - gettext
  - nss_wrapper
  - bind-utils
  tags:
  - flatpak-cache
  - config

- name: Ensure /var/spool/squid directory exists
  ansible.builtin.file:
    path: /var/spool/squid
    state: directory
    owner: squid
    group: squid
    mode: "0755"
  tags:
  - flatpak-cache
  - config

- name: Ensure /etc/pki/squid directory exists
  ansible.builtin.file:
    path: /etc/pki/squid
    state: directory
    owner: squid
    group: squid
    mode: "0755"
  tags:
  - flatpak-cache
  - config

- name: Install squid configuration file
  ansible.builtin.template: src=squid.conf dest=/etc/squid/squid.conf owner=squid group=squid
  tags:
  - flatpak-cache
  - config

- name: Install SSL Certificates
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: /etc/pki/squid/
    owner: squid
    group: squid
    mode: "0640"
  with_items:
  - "{{private}}/files/flatpak-cache-certs/production/pki/ca.crt"
  - "{{private}}/files/flatpak-cache-certs/production/pki/private/ca.key"
  - "{{private}}/files/flatpak-cache-certs/production/pki/dh.pem"
  tags:
  - flatpak-cache
  - config

- name: Enable and start squid service
  systemd_service:
    name: squid.service
    enabled: true
    state: started
  tags:
  - flatpak-cache
  - config
