Skip to content

Commit f2a42ff

Browse files
ffquintellaclaude
andcommitted
(CAT) Fix Windows docker facts failing when powershell not on PATH
The docker custom facts wrap Docker CLI calls in powershell but invoked it as the bare name 'powershell'. When the Puppet agent runs as the SYSTEM service its PATH often omits the WindowsPowerShell directory, so Facter's internal which('powershell') fails and reports "command not found" even though docker itself is on the PATH. Invoke powershell by its absolute path derived from %SystemRoot% so it is always resolvable. Also ignore .claude/settings.local.json. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 233293a commit f2a42ff

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
.plan_cache.json
3434
.rerun.json
3535
bolt-debug.log
36+
.claude/settings.local.json

lib/facter/docker.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232
end
3333

3434
docker_command = if Facter.value(:kernel) == 'windows'
35-
'powershell -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -c docker'
35+
# Invoke PowerShell by its absolute path. When the Puppet agent runs as the
36+
# SYSTEM service, its PATH frequently omits the WindowsPowerShell directory, so
37+
# a bare 'powershell' cannot be resolved by Facter and fails with
38+
# "command not found" even when docker itself is on the PATH.
39+
powershell = "#{ENV.fetch('SystemRoot', 'C:\\Windows')}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
40+
"\"#{powershell}\" -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -c docker"
3641
else
3742
'docker'
3843
end

spec/unit/lib/facter/docker_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
describe 'Facter::Util::Fact' do
77
let(:docker_command) do
88
if Facter.value(:kernel) == 'windows'
9-
'powershell -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -c docker'
9+
powershell = "#{ENV.fetch('SystemRoot', 'C:\\Windows')}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
10+
"\"#{powershell}\" -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -c docker"
1011
else
1112
'docker'
1213
end

0 commit comments

Comments
 (0)