ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
204 stars 157 forks source link

Odd Error in windows.win_audit_rule - #408

Open salderma opened 2 years ago

salderma commented 2 years ago

Hi, my host is an Ubuntu 20.04LTS machine, with Vagrant 2.2.19, VirtualBox 6.1.32, Ansible 2.10.4, and Vagrant is using Ansible Galaxy to pull community.windows 1.10.0. The project involves a Windows 2019 Server vagrant box, it has been configured as a PDC and has a 2nd virtual disk drive added as S:.

The playbook task applied is:

    - name: Shared Drive Auditing
      community.windows.win_audit_rule:
        path: S:\
        user: Everyone
        rights: FullControl
        audit_flags: Failure

The documentation seems to not be concerned with using any quotes for the parameter values, and also shows using lowercase words for rights and audit_flags. I'm not sure if this matters, but I've tried it both ways, same result.

Here's a full stack trace of the error:

The full traceback is:
Cannot convert argument "4", with value: "System.Object[]", for "FileSystemAuditRule" to type "System.Security.AccessControl.AuditFlags": "Cannot convert value "Failure 257,9         Bot" to type "System.Security.AccessControl.AuditFlags". Error: "Unable to match the identifier name Failure 257,9         Bot to a valid enumerator name. Specify one of the following enumerator names and try again:
None, Success, Failure""
At line:130 char:26
+ ... ccessRule = New-Object System.Security.AccessControl.FileSystemAuditR ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

ScriptStackTrace:
at <ScriptBlock>, <No file>: line 130

System.Management.Automation.MethodException: Cannot convert argument "4", with value: "System.Object[]", for "FileSystemAuditRule" to type "System.Security.AccessControl.AuditFlags": "Cannot convert value "Failure 257,9         Bot" to type "System.Security.AccessControl.AuditFlags". Error: "Unable to match the identifier name Failure 257,9         Bot to a valid enumerator name. Specify one of the following enumerator names and try again:
None, Success, Failure"" ---> System.Management.Automation.PSInvalidCastException: Cannot convert value "Failure 257,9         Bot" to type "System.Security.AccessControl.AuditFlags". Error: "Unable to match the identifier name Failure 257,9         Bot to a valid enumerator name. Specify one of the following enumerator names and try again:
None, Success, Failure" ---> System.Management.Automation.RuntimeException: Unable to match the identifier name Failure 257,9         Bot to a valid enumerator name. Specify one of the following enumerator names and try again:
None, Success, Failure
   at System.Management.Automation.EnumMinimumDisambiguation.EnumDisambiguate(String text, Type enumType)
   at System.Management.Automation.LanguagePrimitives.ConvertStringToEnum(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
   --- End of inner exception stack trace ---
   at System.Management.Automation.LanguagePrimitives.ConvertStringToEnum(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
   at System.Management.Automation.LanguagePrimitives.ConversionData`1.Invoke(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
   at System.Management.Automation.LanguagePrimitives.ConvertTo(Object valueToConvert, Type resultType, Boolean recursion, IFormatProvider formatProvider, TypeTable backupTypeTable)
   at System.Management.Automation.Adapter.PropertySetAndMethodArgumentConvertTo(Object valueToConvert, Type resultType, IFormatProvider formatProvider)
   at System.Management.Automation.Adapter.MethodArgumentConvertTo(Object valueToConvert, Boolean isParameterByRef, Int32 parameterIndex, Type resultType, IFormatProvider formatProvider)
   at System.Management.Automation.Adapter.SetNewArgument(String methodName, Object[] arguments, Object[] newArguments, ParameterInformation parameter, Int32 index)
   --- End of inner exception stack trace ---
   at System.Management.Automation.Adapter.SetNewArgument(String methodName, Object[] arguments, Object[] newArguments, ParameterInformation parameter, Int32 index)
   at System.Management.Automation.Adapter.GetMethodArgumentsBase(String methodName, ParameterInformation[] parameters, Object[] arguments, Boolean expandParamsOnBest)
   at System.Management.Automation.Adapter.GetBestMethodAndArguments(String methodName, MethodInformation[] methods, PSMethodInvocationConstraints invocationConstraints, Object[] arguments, Object[]& newArguments)
   at System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] constructors, Object[] arguments)
   at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)
fatal: [dc1]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: Cannot convert argument \"4\", with value: \"System.Object[]\", for \"FileSystemAuditRule\" to type \"System.Security.AccessControl.AuditFlags\": \"Cannot convert value \"Failure 257,9         Bot\" to type \"System.Security.AccessControl.AuditFlags\". Error: \"Unable to match the identifier name Failure 257,9         Bot to a valid enumerator name. Specify one of the following enumerator names and try again:\r\nNone, Success, Failure\"\""
}

I'm not totally sure what most of this means, I have limited experience on the Windows Admin side, and have just started dabbling with using Ansible to configure Windows systems. Looks like it's referencing this line of code: https://github.com/ansible-collections/community.windows/blame/08257cb1863b0c61d80c4a407fef9a9e5d6a8e0b/plugins/modules/win_audit_rule.ps1#L130

Any ideas/help?