sixty4bit
sixty4bit

Reputation: 7956

Chef + rbenv: "rbenv: no such command 'install'" despite ruby-build being installed

I am learning Chef and building a cookbook with recipes for installing rbenv and ruby-build. The ruby-build recipe installs the program and then attempts to install Ruby 2.3.1 with rbenv. However, every time I run chef-client to converge, this last step fails with the error rbenv: no such command 'install' even though the installation of ruby-build finishes successfully.

bash "initialize rbenv and install ruby 2.3.1" do
  user "david"
  cwd  node["user"]["home"]
  environment({
    "PATH" => "#{node['rbenv']['bin']}:#{node['rbenv']['root']}/shims:#{ENV['PATH']}"
  })

  # code "eval \"$(rbenv init -)\" && rbenv install 2.3.1"
  code <<-EOF
  eval "$(rbenv init -)"
  rbenv install 2.3.1
  EOF
end

I've commented out the one-line way that I also tried. In both cases it says that install is missing despite the program being there.

In fact, I can go into the machine manually and run these commands just fine:

[root@myserver ~]# su david
[david@myserver root]$ cd
[david@myserver ~]$ eval "$(.rbenv/bin/rbenv init -)"
[david@myserver ~]$ .rbenv/bin/rbenv install 2.3.1
Downloading ruby-2.3.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.bz2

Any ideas why this would be failing during convergence but not at the command line??

Upvotes: 3

Views: 983

Answers (1)

coderanger
coderanger

Reputation: 54251

Try setting $HOME in shell environment:

environment({
    "PATH" => "#{node['rbenv']['bin']}:#{node['rbenv']['root']}/shims:#{ENV['PATH']}",
    "HOME" => node["user"]["home"],
  })

Upvotes: 1

Related Questions