The exec and execute methods of the Facter::Core::Execution module are commonly used to execute external processes in custom facts. In Facter 4, these methods no longer set the global Ruby variables $CHILD_STATUS or $?.
This is a regression of FACT-1284 which was its self a regression of behavior present in Facter 2.x and 1.x.
Reproduction Case
- Install puppet-agent 7 on CentOS 7:
yum install -y http://yum.puppetlabs.com/puppet7-release-el-7.noarch.rpm
|
yum install -y puppet-agent
|
|
source /etc/profile.d/puppet-agent.sh
|
- Create a directory containing a custom fact that uses the $? variable:
mkdir exit_code_test
|
|
cat <<'EOF' > exit_code_test/exit_code_test.rb
|
Facter.add("exit_code_test") do
|
setcode do
|
Facter::Util::Resolution.exec('/usr/bin/false')
|
"/usr/bin/false exited with code: %{status}" % {status: $?.exitstatus}
|
end
|
end
|
EOF
|
env FACTERLIB=$PWD/exit_code_test facter exit_code_test
|
Outcome
The fact fails to resolve, logging an error from a `nil` reference:
# facter --version
|
4.0.49
|
|
# env FACTERLIB=$PWD/exit_code_test facter exit_code_test
|
[2021-02-02 21:33:19.961928 ] ERROR Facter - Error while resolving custom fact fact='exit_code_test', resolution='<anonymous>': undefined method `exitstatus' for nil:NilClass
|
Expected Outcome
The exit status resolves to 1 as it does in Facter 3:
# facter --version
|
3.14.14 (commit e36657bea27254f003c8fc71d8ef57454db643e2)
|
|
# env FACTERLIB=$PWD/exit_code_test facter exit_code_test
|
/usr/bin/false exited with code: 1
|
And in Facter 2:
# facter --version
|
2.5.7
|
|
# env FACTERLIB=$PWD/exit_code_test facter exit_code_test
|
/usr/bin/false exited with code: 1
|