ohai
ohai copied to clipboard
Ohai always detects the embedded Ruby in the languages plugin since Chef 16
Description
There seems to have been a change in Chef 16 that makes it prepend the embedded Ruby directories to PATH
when using shell_out
: https://github.com/chef/chef/blob/chef-16/chef-utils/lib/chef-utils/dsl/default_paths.rb
For the Ruby Ohai plugin, I can't think of a single situation where you would want this. You want plugins to pretend the embedded Chef Ruby doesn't exist when they're examining the system.
Ohai Version
16.13.0, but I see the same code path in master
Platform Version
Debian 10, CentOS 8
Ohai Output
Here's the node['languages']['ruby']
that I get since this change:
{
"platform": "x86_64-linux",
"version": "2.7.3",
"release_date": "2021-04-05",
"target": "x86_64-pc-linux-gnu",
"target_cpu": "x86_64",
"target_vendor": "pc",
"target_os": "linux",
"host": "x86_64-pc-linux-gnu",
"host_cpu": "x86_64",
"host_os": "linux",
"host_vendor": "pc",
"bin_dir": "/opt/cinc/embedded/bin",
"ruby_bin": "/opt/cinc/embedded/bin/ruby",
"gem_bin": "/opt/cinc/embedded/bin/gem",
"gems_dir": "/opt/cinc/embedded/lib/ruby/gems/2.7.0"
}
This is what I should be getting:
{
"platform": "x86_64-linux",
"version": "2.6.2",
"release_date": "2019-03-13",
"target": "x86_64-pc-linux-gnu",
"target_cpu": "x86_64",
"target_vendor": "pc",
"target_os": "linux",
"host": "x86_64-pc-linux-gnu",
"host_cpu": "x86_64",
"host_os": "linux-gnu",
"host_vendor": "pc",
"bin_dir": "/usr/local/bin",
"ruby_bin": "/usr/local/bin/ruby",
"gem_bin": "/usr/local/bin/gem",
"gems_dir": "/usr/local/lib/ruby/gems/2.6.0"
}
Workaround
sed -i 's/so = shell_out(cmd)/so = shell_out(cmd, default_env: false)/' /opt/$CHEF_OR_CINC/embedded/lib/ruby/gems/*/gems/ohai-*/lib/ohai/plugins/ruby.rb
I am not familiar enough with the internals here to know if the above is the right solution or not... but it does work :)
that's probably easy enough to fix with internal: false