# platform = multi_platform_all
# reboot = false
# strategy = configure
# complexity = low
# disruption = low




- name: "Log USBGuard daemon audit events using Linux Audit"
  block:
    - name: "Check for duplicate values"
      ansible.builtin.lineinfile:
        path: '/etc/usbguard/usbguard-daemon.conf'
        create: True
        regexp: '(?i)^[ \\t]*AuditBackend='
        state: 'absent'
      check_mode: yes
      changed_when: no
      register: 'dupes'
    - name: "Deduplicate values from /etc/usbguard/usbguard-daemon.conf"
      ansible.builtin.lineinfile:
        path: '/etc/usbguard/usbguard-daemon.conf'
        create: True
        regexp: '(?i)^[ \\t]*AuditBackend='
        state: 'absent'
      when: 'dupes.found is defined and dupes.found > 1'
    - name: "Insert correct line to /etc/usbguard/usbguard-daemon.conf"
      ansible.builtin.lineinfile:
        path: '/etc/usbguard/usbguard-daemon.conf'
        create: True
        regexp: '(?i)^[ \\t]*AuditBackend='
        line: 'AuditBackend=LinuxAudit'
        state: present
