--- # Without this, the older nine-category policy can override the subcategories # below, and the run succeeds while recording less than it says. - name: Make subcategory audit settings take precedence ansible.windows.win_regedit: path: HKLM:\SYSTEM\CurrentControlSet\Control\Lsa name: SCENoApplyLegacyAuditPolicy data: 1 type: dword - name: Set each audit subcategory ansible.windows.win_audit_policy_system: subcategory: "{{ item.name }}" audit_type: "{{ item.audit }}" loop: "{{ windows_audit_subcategories }}" loop_control: label: "{{ item.name }}" - name: Record full command lines in process creation events ansible.windows.win_regedit: path: HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit name: ProcessCreationIncludeCmdLine_Enabled data: "{{ 1 if windows_audit_process_command_line else 0 }}" type: dword - name: Record PowerShell script blocks ansible.windows.win_regedit: path: HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging name: EnableScriptBlockLogging data: "{{ 1 if windows_audit_powershell_script_blocks else 0 }}" type: dword - name: Make the Security log big enough to keep a day ansible.windows.win_powershell: parameters: Bytes: "{{ windows_audit_security_log_max_bytes }}" script: | [CmdletBinding(SupportsShouldProcess)] param([long]$Bytes) $now = [long](((wevtutil gl Security | Where-Object { $_ -like '*maxSize:*' }) -split ':')[1].Trim()) if ($now -ge $Bytes) { $Ansible.Changed = $false; return } if ($PSCmdlet.ShouldProcess('Security', "raise maximum size to $Bytes bytes")) { wevtutil sl Security "/ms:$Bytes" if ($LASTEXITCODE -ne 0) { throw 'wevtutil could not resize the Security log' } } # Reads the policy back from the machine. A domain Group Policy object that # sets audit policy wins at the next refresh, and this is where that shows. - name: Read back the effective audit policy ansible.windows.win_command: auditpol /get /category:* changed_when: false register: windows_audit_effective - name: Confirm process creation is being recorded ansible.builtin.assert: that: - windows_audit_effective.stdout is search('Process Creation\s+Success') fail_msg: >- auditpol does not show Process Creation as Success on {{ inventory_hostname }}. A Group Policy object is probably setting audit policy. Put these settings in that object instead, or they are undone at the next policy refresh. success_msg: Process creation is audited. when: not ansible_check_mode