---
-
  name: "Block to Allow Loading of Variables without running task"
  when: run_tasks
  block:
    -
      name: Include OS-Specific variables
      ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"
    
    -
      name: Include setup vars
      ansible.builtin.include_tasks: setup-vars.yml
    
    -
      name: Ensure ClamAV packages are installed.
      ansible.builtin.package:
        name: "{{ item }}"
        state: present
      with_items: "{{ clamav_packages }}"
      register: clamav_packages_install
    
    -
      name: Run freshclam after ClamAV packages change.
      ansible.builtin.command: freshclam
      when: clamav_packages_install.changed
      register: freshclam_result
      notify: Restart clamav daemon
      # On Debian, freshclam is automatically run post-install, so this may fail.
      failed_when:
        - freshclam_result is failed
        - freshclam_result.stderr.find('locked by another process') != -1
      tags: ["skip_ansible_lint"]
    
    -
      name: Include setup-RedHat.yml
      ansible.builtin.include_tasks: setup-RedHat.yml
      when: ansible_os_family == 'RedHat'
    
    -
      name: Change configuration for the ClamAV daemon.
      ansible.builtin.lineinfile:
        path: "{{ clamav_daemon_config_path }}"
        regexp: "{{ item.regexp }}"
        line: "{{ item.line | default('') }}"
        state: "{{ item.state | default('present') }}"
        mode: "0644"
        create: true
      notify: Restart clamav daemon
      with_items: "{{ clamav_daemon_configuration_changes }}"
    
    -
      name: Change configuration for the freshclam daemon.
      ansible.builtin.lineinfile:
        path: "{{ clamav_freshclam_daemon_config_path }}"
        regexp: '{{ item.regexp }}'
        line: "{{ item.line | default('') }}"
        state: "{{ item.state | default('present') }}"
      with_items: "{{ clamav_freshclam_configuration_changes }}"
      when: clamav_freshclam_configuration_changes is defined
    
    -
      name: Ensure ClamAV daemon is running (if configured).
      ansible.builtin.service:
        name: "{{ clamav_daemon }}"
        state: "{{ clamav_daemon_state }}"
        enabled: "{{ clamav_daemon_enabled }}"
      when: not ansible_check_mode
    
    -
      name: Ensure ClamAV freshclam daemon is running (if configured).
      ansible.builtin.service:
        name: "{{ clamav_freshclam_daemon }}"
        state: "{{ clamav_freshclam_daemon_state }}"
        enabled: "{{ clamav_freshclam_daemon_enabled }}"
      when: not ansible_check_mode
    