Skip to content

Commit 2dde178

Browse files
authored
fixing chef-cli exec command failing when ruby not in path (#331)
Signed-off-by: nikhil2611 <ngupta@progress.com>
1 parent 95f72ed commit 2dde178

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

habitat/plan.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ wrap_ruby_bin() {
6969
set -e
7070
7171
# Set binary path that allows InSpec to use non-Hab pkg binaries
72-
export PATH="/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:$pkg_prefix/vendor/bin:\$PATH"
72+
# Include Ruby bin directory so chef-cli exec can find gem, etc.
73+
export PATH="$(pkg_path_for ${ruby_pkg})/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:$pkg_prefix/vendor/bin:\$PATH"
7374
7475
# Set Ruby paths defined from 'do_setup_environment()'
7576
export GEM_HOME="$pkg_prefix/vendor"

lib/chef-cli/helpers.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,12 @@ def habitat_env(show_warning: false)
173173
raise "Error: Could not determine the vendor package prefix. Ensure #{ChefCLI::Dist::HAB_PKG_NAME} is installed and CHEF_CLI_VERSION is set correctly." unless vendor_pkg_prefix
174174

175175
vendor_dir = File.join(vendor_pkg_prefix, "vendor")
176-
# Construct PATH
176+
# Construct PATH including Ruby bin directory for chef-cli exec command
177+
ruby_bin_dir = File.dirname(RbConfig.ruby)
177178
path = [
178179
File.join(bin_pkg_prefix, "bin"),
179180
File.join(vendor_dir, "bin"),
181+
ruby_bin_dir, # Add Ruby bin directory so exec can find gem etc.
180182
ENV["PATH"].split(File::PATH_SEPARATOR), # Preserve existing PATH
181183
].flatten.uniq
182184

spec/unit/helpers_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@
112112
context "when installed with habitat" do
113113
let(:chef_dke_path) { "/hab/pkgs/chef/chef-workstation/1.0.0/123" }
114114
let(:cli_hab_path) { "/hab/pkgs/chef/chef-cli/1.0.0/123" }
115+
let(:ruby_bin_dir) { File.dirname(RbConfig.ruby) }
115116
let(:expected_gem_root) { Gem.default_dir }
116-
let(:expected_path) { [File.join(chef_dke_path, "bin"), File.join(cli_hab_path, "vendor", "bin"), "/usr/bin:/bin"].flatten }
117+
let(:expected_path) { [File.join(chef_dke_path, "bin"), File.join(cli_hab_path, "vendor", "bin"), ruby_bin_dir, "/usr/bin:/bin"].flatten }
117118
let(:expected_env) do
118119
{
119120
"PATH" => expected_path.join(File::PATH_SEPARATOR),

0 commit comments

Comments
 (0)