ansible/ansible · error · Win32Exception

AllocateLocallyUniqueId() failed

Error message

AllocateLocallyUniqueId() failed

What it means

AllocateLocallyUniqueId is a near-infallible Win32 helper that allocates a LUID for the TOKEN_SOURCE structure used in LsaLogonUser; it only fails on extreme conditions (kernel memory exhaustion / handle-table trouble). Its failure aborts the S4U logon before it starts.

Source

Thrown at lib/ansible/module_utils/csharp/Ansible.Become.cs:573

                        {
                            Length = (UInt16)usernameLength,
                            MaximumLength = (UInt16)usernameLength,
                            Buffer = usernamePtr,
                        },
                        ClientRealm = new NativeHelpers.LSA_UNICODE_STRING
                        {
                            Length = (UInt16)domainLength,
                            MaximumLength = (UInt16)domainLength,
                            Buffer = domainPtr,
                        },
                    };
                    Marshal.StructureToPtr(s4uLogon, authInfo, false);
                    Marshal.Copy(username.ToCharArray(), 0, usernamePtr, username.Length);
                    Marshal.Copy(domainName.ToCharArray(), 0, domainPtr, domainName.Length);

                    Luid sourceLuid;
                    if (!NativeMethods.AllocateLocallyUniqueId(out sourceLuid))
                        throw new Process.Win32Exception("AllocateLocallyUniqueId() failed");

                    NativeHelpers.TOKEN_SOURCE tokenSource = new NativeHelpers.TOKEN_SOURCE
                    {
                        SourceName = "ansible\0".ToCharArray(),
                        SourceIdentifier = sourceLuid,
                    };

                    // Only Batch or Network will work with S4U, prefer Batch but use Network if asked
                    LogonType lsaLogonType = logonType == LogonType.Network
                        ? LogonType.Network
                        : LogonType.Batch;
                    SafeLsaMemoryBuffer profileBuffer;
                    UInt32 profileBufferLength;
                    Luid logonId;
                    SafeNativeHandle hToken;
                    IntPtr quotas;
                    UInt32 subStatus;

View on GitHub (pinned to 9cf16a4aca)

Solutions

  1. Retry the task — transient allocation failures usually clear
  2. If persistent, free resources / investigate system memory and kernel pool usage on the target host
Defensive patterns

Strategy: retry

Try / catch

catch (Win32Exception e) when (e.Message.Contains("AllocateLocallyUniqueId"))
{ // transient resource exhaustion: retry after delay
}

Prevention

When it happens

Trigger: Genuine kernel resource exhaustion at the moment the S4U logon path builds its TOKEN_SOURCE; practically never seen in normal operation.

Common situations: Severely memory-pressure-exhausted Windows hosts; recurring appearances indicate deeper OS instability rather than an Ansible configuration problem.

Related errors


AI-assisted analysis of ansible/ansible@9cf16a4aca (2026-08-15). Data as JSON: /api/errors/4653dda262667d43. Report an issue: GitHub.