Skip to content

Instantly share code, notes, and snippets.

@logikal
Last active December 18, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logikal/5833204 to your computer and use it in GitHub Desktop.
Save logikal/5833204 to your computer and use it in GitHub Desktop.
Issues with chef_gem: when passing options to chef_gem, chef reports that it is unable to find the `gem` command. When not passing options, gems are installed as expected (I have a different issue with my no-option install though).

node info:

# cat /etc/redhat-release
CentOS release 6.3 (Final)
# gem list
-bash: gem: command not found
# /opt/chef/embedded/bin/ruby gem list
/opt/chef/embedded/bin/ruby: No such file or directory -- gem (LoadError)
# chef-client -v
Chef: 10.26.0

This will fail

Notice the STDERR: sh: gem: command not found error message

chef:recipe > chef_gem "mysql" do
chef:recipe >   options ""
chef:recipe ?> end
[2013-06-21T13:20:04-05:00] INFO: Processing chef_gem[mysql] action install ((irb#1) line 20)

================================================================================
Error executing action `install` on resource 'chef_gem[mysql]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '127'
---- Begin output of gem install mysql -q --no-rdoc --no-ri -v "2.9.1"  ----
STDOUT:
STDERR: sh: gem: command not found
---- End output of gem install mysql -q --no-rdoc --no-ri -v "2.9.1"  ----

A coworker had some ideas.

  • Use the gem_binary command!
chef:recipe > chef_gem "mysql" do
chef:recipe >   gem_binary("/opt/chef/embedded/bin/gem")
chef:recipe ?>   options("-- --with-mysql-lib=/usr/include/mysql")
chef:recipe ?> end
ArgumentError: The chef_gem resource is restricted to the current gem environment, use gem_package to install to other environments.
  from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.26.0/lib/chef/resource/chef_gem.rb:37:in `gem_binary'
	from (irb#1):2:in `block in irb_binding'
	from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.26.0/lib/chef/mixin/recipe_definition_dsl_core.rb:74:in `instance_eval'
	from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.26.0/lib/chef/mixin/recipe_definition_dsl_core.rb:74:in `method_missing'
	from (irb#1):1
  • Use an option hash instead!
chef:recipe > chef_gem "mysql" do
chef:recipe >   options (:build_args => "--with-mysql-lib=/usr/include/mysql")
chef:recipe ?> end
SyntaxError: (irb#1):2: syntax error, unexpected tASSOC, expecting ')'
  options (:build_args => "--with-mysql-lib=/usr/include/mysql")
                         ^
(irb#1):2: syntax error, unexpected ')', expecting keyword_end

This actually runs gem, as intended

chef:recipe > chef_gem "mysql"
[2013-06-21T13:17:18-05:00] INFO: Processing chef_gem[mysql] action install ((irb#1) line 1)

================================================================================
Error executing action `install` on resource 'chef_gem[mysql]'
================================================================================

Gem::Installer::ExtensionBuildError
-----------------------------------
ERROR: Failed to build gem native extension.

        /opt/chef/embedded/bin/ruby extconf.rb
checking for mysql_ssl_set()... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

This will fail

Notice the STDERR: sh: gem: command not found error message

chef:recipe > chef_gem "mysql" do
chef:recipe >   options "-- --with-mysql-lib=/usr/include/mysql"
chef:recipe ?> end
[2013-06-21T13:17:49-05:00] INFO: Processing chef_gem[mysql] action install ((irb#1) line 9)

================================================================================
Error executing action `install` on resource 'chef_gem[mysql]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '127'
---- Begin output of gem install mysql -q --no-rdoc --no-ri -v "2.9.1" -- --with-mysql-lib=/usr/include/mysql ----
STDOUT:
STDERR: sh: gem: command not found

This will fail

Notice the STDERR: sh: gem: command not found error message

chef:recipe > chef_gem "mysql" do
chef:recipe >   options "--with-mysql-lib=/usr/include/mysql"
chef:recipe ?> end
[2013-06-21T13:19:50-05:00] INFO: Processing chef_gem[mysql] action install ((irb#1) line 15)

================================================================================
Error executing action `install` on resource 'chef_gem[mysql]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '127'
---- Begin output of gem install mysql -q --no-rdoc --no-ri -v "2.9.1" --with-mysql-lib=/usr/include/mysql ----
STDOUT:
STDERR: sh: gem: command not found
---- End output of gem install mysql -q --no-rdoc --no-ri -v "2.9.1" --with-mysql-lib=/usr/include/mysql ----
Ran gem install mysql -q --no-rdoc --no-ri -v "2.9.1" --with-mysql-lib=/usr/include/mysql returned 127
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment