Gem install using chef

Hi all,

Trying to install gem using below recipe but getting error.

chef_gem ‘install gem’ do
source '/data/kitchen-docker-2.6.0.gem’
package_name 'kitchen-docker’
action :install

tried using gem_package resource as well but same result.

[2017-04-13T16:02:29+10:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: chef_gem[install gem] ((chef-apply cookbook)::(chef-apply recipe) line 7) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘1’
---- Begin output of /opt/chefdk/embedded/bin/gem install /data/dockergems/vendor/cache/kitchen-docker-2.6.0.gem -q --no-rdoc --no-ri -v “2.6.0” ----
STDERR: ERROR: While executing gem … (URI::BadURIError)
both URI are relative

That is because source is meant to be a URL: the same is true for gem package as well I believe. It is is not typically a good idea to package gems with cookbooks. Are you doing this because you do not have internet access in your deployment?

Hi majormoses
Thanks for reply. Yes you are correct. we dont have internet access to the servers.
plan is to use artifactory (remote repo) in future. but for now i was manually trying to install gem locally and was trying to do the same using cookbook as temporary workaround.

Makes sense, though I think for the short term you will likely need to resort to using a chef cookbook file and an exec block…

By using GEM Package in chef,

My first thought was to use the raw ruby gem modules to check for updates, install if the gem was missing or run an update if there was a newer version. That could have worked but it just seemed like I must be reinventing a wheel so I revisited the gem_package docs.

Try something like this

chef_gem “install gem” do
source "#{Chef::Config[:file_cache_path]}/kitchen-docker-2.6.0.gem"
action :install

Make sure you downloaded the gem to the source path.