From 739762dd627d32c36f77810d34432b2bdff596cb Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sun, 12 Jul 2026 12:11:52 +0200 Subject: [PATCH] search_path: explicitly search in /opt/puppetlabs/bin Previously, we only had to paths where we looked for binaries + `$PATH`. Those two paths were `/sbin` and `/usr/sbin`. This covers most binaries, but relying on $PATH is... unreliable. e.g. many people assume that `/opt/puppetlabs/bin` is available in `search_paths`. But this isn't guaranteed. It's added to `$PATH` by `/etc/profile.d/puppet-agent.sh`. So it's only available in interactive shells. This causes the following bug: https://github.com/voxpupuli/puppet-openvoxdb/blob/56261b7b5dda7211d610cf5b28b8356a7ab41b52/lib/facter/openvoxdb_version.rb#L5 When running `puppet agent -t`, this fact works and `puppetdb` is found at `/opt/puppetlabs/bin/puppetdb`. When running the puppet.service unit, `/etc/profile.d/puppet-agent.sh` isn't sourced so the fact is nil. And IMO this is a bug in OpenFact. The whole list is still prefixed by `$PATH`. Signed-off-by: Tim Meusel --- lib/facter/custom_facts/core/execution/posix.rb | 2 +- spec/custom_facts/core/execution/posix_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/facter/custom_facts/core/execution/posix.rb b/lib/facter/custom_facts/core/execution/posix.rb index 9a4e39656..52fa10e1f 100644 --- a/lib/facter/custom_facts/core/execution/posix.rb +++ b/lib/facter/custom_facts/core/execution/posix.rb @@ -4,7 +4,7 @@ module Facter module Core module Execution class Posix < Facter::Core::Execution::Base - DEFAULT_SEARCH_PATHS = ['/sbin', '/usr/sbin'].freeze + DEFAULT_SEARCH_PATHS = ['/sbin', '/usr/sbin', '/opt/puppetlabs/bin'].freeze def search_paths # Make sure custom_facts is usable even for non-root users. Most commands diff --git a/spec/custom_facts/core/execution/posix_spec.rb b/spec/custom_facts/core/execution/posix_spec.rb index 30b3e38e9..1206e6aa6 100644 --- a/spec/custom_facts/core/execution/posix_spec.rb +++ b/spec/custom_facts/core/execution/posix_spec.rb @@ -6,7 +6,7 @@ describe '#search_paths' do it 'uses the PATH environment variable plus /sbin and /usr/sbin on unix' do allow(ENV).to receive(:[]).with('PATH').and_return '/bin:/usr/bin' - expect(posix_executor.search_paths).to eq %w[/bin /usr/bin /sbin /usr/sbin] + expect(posix_executor.search_paths).to eq %w[/bin /usr/bin /sbin /usr/sbin /opt/puppetlabs/bin] end end