Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to change gem sources for chef-client?

Is any one aware of a way to change the gem sources for a chef-client run?

My node of concern is behind a firewall, so I want to replace rubygems.org with an internal Nexus repo (https://github.com/sonatype/nexus-ruby-support). I tried updating the source list for 'chef embedded gem', but the offending chef_gem calls seem to be using a different source list that still refers to rubygems.org.

like image 474
byggztryng Avatar asked Aug 27 '13 20:08

byggztryng


People also ask

How do I remove a gem source?

Managing Gem Sources To list all gem sources, use the -l flag. To remove a gem source, use the r flag followed by the URL of the source to be removed.

What is gem in chef?

The chef_gem and gem_package resources are both used to install Ruby gems. For any machine on which the chef-client is installed, there are two instances of Ruby. One is the standard, system-wide instance of Ruby and the other is a dedicated instance that is available only to the chef-client.

Where are gem files stored?

By default, binaries installed by gem will be placed into: /usr/local/lib/ruby/gems/3.1. 0/bin You may want to add this to your PATH.

How do I publish a new gem?

Publish the new release to RubyGem If you haven't done it already, you will need to create an account at https://rubygems.org/users/new. This last step will take a few seconds to complete. You should receive an email shortly after, confirming that a new release was published.


3 Answers

You can override the source URLs in /root/.gemrc

The format is as follows:

:sources:
- http://your.mirror.com/

The documentation is very spartan, but if you look up the "gem source" command you can eventually hunt this up. Remember that Chef embeds its own gem interpreter, so the gem command used by chef is NOT in the system path.

like image 111
TJNII Avatar answered Nov 15 '22 08:11

TJNII


remove existing rubygems.org etc. (if you don't want external gems)

/opt/chef/embedded/bin/gem sources -r ...

Add mygems

/opt/chef/embedded/bin/gem sources -a "http://mygems.example.com/"

like image 36
daxroc Avatar answered Nov 15 '22 08:11

daxroc


I was on the right path with the initial idea; the gem sources just need to be changed for root, rather than the 'sudo user', and chef-client will pick them up.

like image 32
byggztryng Avatar answered Nov 15 '22 08:11

byggztryng