# Gem sources chicken & egg problem

**URL:** <https://discourse.chef.io/t/gem-sources-chicken-egg-problem/5888>\
**Category:** Chef Infra (archive)\
**Created:** [October 8, 2014, 10:27pm UTC](https://discourse.chef.io/t/gem-sources-chicken-egg-problem/5888 "2014-10-08T22:27:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DV1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/dv1/32/186_2.png) [@DV1](https://discourse.chef.io/u/DV1)\
**Post date:** [October 8, 2014, 10:27pm UTC](https://discourse.chef.io/t/gem-sources-chicken-egg-problem/5888/1 "2014-10-08T22:27:38Z")

</div>

Hi guys,

Thought I’d get your advice on the following:

I have chef-client run fail on the initial (only) run due to host’s default  
gem sources not having the version of gem chef-client is trying to install.  
To be more specific, it’s passenger gem from passenger\_apache2::source  
cookbook here:

gem\_package “passenger” do  
version node[‘passenger’][‘version’]  
end

The default gem sources on the host simply don’t have passenger gem and/or  
its dependencies so of course it fails.

My goal is to make chef-client aware of an additional gem source at first  
run. So far I’ve tried the following:

execute ‘add\_rubygems.org\_gemrepo’ do  
action :run  
command '/usr/bin/gem sources --add [https://rubygems.org/](https://rubygems.org/)'  
end

I see the code being executed on chef-client run, nevertheless, first  
chef-client run fails to find passenger gem. So there must be some caching  
going on that I need to override.

All further chef-client runs succeed, though.

So my question is, how can I make chef-cilent aware of additional gem  
sources on its very first run?

–  
Best regards, Dmitriy V.

---

<div class="post-metadata">

**Author:** ![Stewart\_Curtis](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/stewart_curtis/32/237_2.png) [@Stewart\_Curtis](https://discourse.chef.io/u/Stewart_Curtis)\
**Post date:** [October 8, 2014, 10:37pm UTC](https://discourse.chef.io/t/gem-sources-chicken-egg-problem/5888/2 "2014-10-08T22:37:53Z")

</div>

It sounds like you might want to update the gem source during the compile phase of the chef-client run. The client runs in two phases: (1) compile phase that determines all recipes/resources to run with necessary attribute values, and (2) execution phase that actually performs the specific actions.

Try:

execute ‘add\_rubygems.org\_gemrepo’ do  
action :nothing  
command '/usr/bin/gem sources --add [https://rubygems.org/](https://rubygems.org/)'  
end.run\_action(:run)

Add this before your gem\_package resource and it will update the gem sources during the compile phase (1), then install the gem during the execution phase (2).

This blog post has some additional information that might be useful, [https://www.getchef.com/blog/2013/09/04/demystifying-common-idioms-in-chef-recipes/](https://www.getchef.com/blog/2013/09/04/demystifying-common-idioms-in-chef-recipes/).[https://www.getchef.com/blog/2013/09/04/demystifying-common-idioms-in-chef-recipes/](https://www.getchef.com/blog/2013/09/04/demystifying-common-idioms-in-chef-recipes/)

## Curtis

Curtis Stewart

Consultant  
m 217.390.5067

Skype cstewart8710  
[cstewart@momentumsi.com](mailto:cstewart@momentumsi.com)

[www.momentumsi.com](http://www.momentumsi.com)[http://www.momentumsi.com](http://www.momentumsi.com)

[[http://www.momentumsi.com/wp-content/uploads/2013/07/logo.jpg](http://www.momentumsi.com/wp-content/uploads/2013/07/logo.jpg)]

Cloud Migration - Architecture - DevOps - Big Data - App Dev

* * *

From: DV [vindimy@gmail.com](mailto:vindimy@gmail.com)  
Sent: Wednesday, October 8, 2014 5:27 PM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] gem sources chicken & egg problem

Hi guys,

Thought I’d get your advice on the following:

I have chef-client run fail on the initial (only) run due to host’s default gem sources not having the version of gem chef-client is trying to install. To be more specific, it’s passenger gem from passenger\_apache2::source cookbook here:

gem\_package “passenger” do  
version node[‘passenger’][‘version’]  
end

The default gem sources on the host simply don’t have passenger gem and/or its dependencies so of course it fails.

My goal is to make chef-client aware of an additional gem source at first run. So far I’ve tried the following:

execute ‘add\_rubygems.org\_gemrepo’ do  
action :run  
command '/usr/bin/gem sources --add [https://rubygems.org/](https://rubygems.org/)'  
end

I see the code being executed on chef-client run, nevertheless, first chef-client run fails to find passenger gem. So there must be some caching going on that I need to override.

All further chef-client runs succeed, though.

So my question is, how can I make chef-cilent aware of additional gem sources on its very first run?

–  
Best regards, Dmitriy V.
