Merge pull request #95 from bunny-lab-io:codex/fix-ansible-execution-environment-error

Fix Ansible EE metadata persistence on Windows PowerShell
This commit is contained in:
2025-10-15 23:49:36 -06:00
committed by GitHub

View File

@@ -64,6 +64,28 @@ $symbols = @{
Info = [char]0x2139 Info = [char]0x2139
} }
function Set-FileUtf8Content {
param(
[Parameter(Mandatory = $true)]
[string]$Path,
[Parameter()]
[AllowNull()]
[object]$Value = ''
)
$text = if ($null -eq $Value) { '' } else { [string]$Value }
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
try {
Set-Content -Path $Path -Value $text -Encoding UTF8NoBOM -ErrorAction Stop
} catch [System.Management.Automation.ParameterBindingException] {
[System.IO.File]::WriteAllText($Path, $text, $utf8NoBom)
} catch {
[System.IO.File]::WriteAllText($Path, $text, $utf8NoBom)
}
}
# Admin/Elevation helpers for Agent deployment # Admin/Elevation helpers for Agent deployment
function Test-IsAdmin { function Test-IsAdmin {
try { try {
@@ -646,22 +668,23 @@ def lockf(*_args, **_kwargs):
try { try {
if (-not (Test-Path (Join-Path $supportDir '__init__.py') -PathType Leaf)) { if (-not (Test-Path (Join-Path $supportDir '__init__.py') -PathType Leaf)) {
Set-Content -Path (Join-Path $supportDir '__init__.py') -Value '' -Encoding UTF8NoBOM Set-FileUtf8Content -Path (Join-Path $supportDir '__init__.py') -Value ''
} }
Set-Content -Path $fcntlStubPath -Value $fcntlStub -Encoding UTF8NoBOM Set-FileUtf8Content -Path $fcntlStubPath -Value $fcntlStub
} catch { } catch {
Write-AgentLog -FileName $LogName -Message "[AnsibleEE] Failed to seed Windows fcntl compatibility shim: $($_.Exception.Message)" Write-AgentLog -FileName $LogName -Message "[AnsibleEE] Failed to seed Windows fcntl compatibility shim: $($_.Exception.Message)"
} }
try { try {
$metadata | ConvertTo-Json -Depth 5 | Set-Content -Path $metadataPath -Encoding UTF8NoBOM $metadataJson = $metadata | ConvertTo-Json -Depth 5
Set-FileUtf8Content -Path $metadataPath -Value $metadataJson
} catch { } catch {
Write-AgentLog -FileName $LogName -Message "[AnsibleEE] Failed to persist metadata.json: $($_.Exception.Message)" Write-AgentLog -FileName $LogName -Message "[AnsibleEE] Failed to persist metadata.json: $($_.Exception.Message)"
throw "Unable to persist Ansible execution environment metadata." throw "Unable to persist Ansible execution environment metadata."
} }
try { try {
Set-Content -Path $versionTxtPath -Value $expectedVersionNorm -Encoding UTF8NoBOM Set-FileUtf8Content -Path $versionTxtPath -Value $expectedVersionNorm
} catch {} } catch {}
Write-AgentLog -FileName $LogName -Message "[AnsibleEE] Execution environment ready at $eeRoot" Write-AgentLog -FileName $LogName -Message "[AnsibleEE] Execution environment ready at $eeRoot"