Possible to change gem sources for chef-client?

2019-06-21 03:54发布

问题:

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.

回答1:

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.



回答2:

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/"



回答3:

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.