[chef] Re: gem_package and --user-install


Chronological Thread 
  • From: Akzhan Abdulin < >
  • To: " " < >
  • Subject: [chef] Re: gem_package and --user-install
  • Date: Tue, 28 Jul 2015 00:44:03 +0300

Correct way is to use Bundler with specified vendor/gems directory.

2015-07-28 0:29 GMT+03:00 Phil Oliva < " target="_blank"> >:

Hi all,

 

I can’t seem to figure out a way to use gem_package with --user-install option but install gem to another user’s home directory (local user for example).

 

gem_package = node[‘my_cookbook’]['gem_package']

gems = gem_package['gems']

gem_binary = gem_package['gem_binary']

remove_options = gem_package['remove_options']

install_options = gem_package['install_options']

source = gem_package['source']

 

gems.each { |gem_name, gem_info|

  gem_ver = gem_info['ver']

 

  gem_package "Remove old versions of #{gem_name} gem" do

    package_name "#{gem_name}"

    action :remove

    ignore_failure true

    gem_binary gem_binary

    options remove_options

    not_if %Q[#{gem_binary} list | grep "#{gem_name} (#{gem_ver})"]

  end

 

  gem_package "Install specified version of #{gem_name} gem" do

    package_name "#{gem_name}"

    version "#{gem_ver}"

    options "--clear-sources --source #{source} #{install_options}"

    action :install

    gem_binary gem_binary

    not_if %Q[#{gem_binary} list | grep "#{gem_name} .*#{gem_ver}"]

  end

}

 

The gem resource produces the right command but needs to be run as local and not root so files end up in wrong directory.

 

/usr/bin/gem install gem_name -q --no-rdoc --no-ri -v "3.15.0" --clear-sources --source http://gemserver.chef.orion.altus.bblabs.rim.net/ --user-install

 

Is an execute block only way to do this using “user” attribute?

For some reason I thought it was common functionality that you can change which user runs a resource in chef. However after checking docs it seem you can only reference :user in guards.

 

Am I missing something obvious?

 

-Phil

 

Philip Oliva

Senior Infrastructure Software Developer

BlackBerry Ltd.

“Fail quick, fail often, recover quickly”

http://ca.linkedin.com/pub/philip-oliva/67/74/10

 





Archive powered by MHonArc 2.6.16.

§