---

- name: is log2mail installed?
  ansible.builtin.stat:
    path: /etc/log2mail/config/
  check_mode: no
  register: log2mail_config

- block:
  - name: log2mail proxy config is present
    ansible.builtin.template:
      src: log2mail.j2
      dest: /etc/log2mail/config/squid.conf
      mode: "0640"
      owner: log2mail
      group: adm
    notify: restart log2mail

  - name: log2mail user is in proxy group
    ansible.builtin.user:
      name: log2mail
      groups: proxy
      append: yes
      state: present
    notify: restart log2mail

  when: log2mail_config.stat.exists
