Gem sources chicken & egg problem


#1

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/'
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.


#2

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

Curtis

Curtis Stewart

Consultant
m 217.390.5067

Skype cstewart8710
cstewart@momentumsi.com

www.momentumsi.comhttp://www.momentumsi.com

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

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


From: DV vindimy@gmail.com
Sent: Wednesday, October 8, 2014 5:27 PM
To: 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/'
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.