How to install a non-Ruby community gem with Chef?


#1

How would I install a non-Ruby community gem with Chef? Right now I’m
trying to use a bash script, but if there’s a way to install it with a Chef
command, I’m thinking that would make more sense.

Any suggestions?

Eric Feldhusen


#2

The gem_package resource has a source parameter where you can specify a
.gem file: http://docs.opscode.com/resource_gem_package.html

Tom Duffield — Automation Consulting Engineer

651.769.7497 – tom@opscode.com – *my:
*Linkedinhttp://www.linkedin.com/in/thomasduffield/
Twitter https://twitter.com/tomduffield

OPSCODE

CODE CAN
opscode.com http://www.opscode.com Blog http://www.opscode.com/blog/
Facebook http://www.facebook.com/opscode
Twitterhttp://www.twitter.com/opscode
YouTube http://www.youtube.com/opscode

On Wed, Oct 30, 2013 at 8:39 AM, Eric Feldhusen
efeldhusen.lists@gmail.comwrote:

How would I install a non-Ruby community gem with Chef? Right now I’m
trying to use a bash script, but if there’s a way to install it with a Chef
command, I’m thinking that would make more sense.

Any suggestions?

Eric Feldhusen


#3

What if I needed to build the gem from source since we’re running different
versions of Ruby?

Eric Feldhusen

On Wed, Oct 30, 2013 at 9:42 AM, Tom Duffield tom@opscode.com wrote:

The gem_package resource has a source parameter where you can specify a
.gem file: http://docs.opscode.com/resource_gem_package.html

Tom Duffield — Automation Consulting Engineer

651.769.7497 – tom@opscode.com – *my: *Linkedinhttp://www.linkedin.com/in/thomasduffield/
Twitter https://twitter.com/tomduffield

OPSCODE

CODE CAN
opscode.com http://www.opscode.com Bloghttp://www.opscode.com/blog/
Facebook http://www.facebook.com/opscode Twitterhttp://www.twitter.com/opscode
YouTube http://www.youtube.com/opscode

On Wed, Oct 30, 2013 at 8:39 AM, Eric Feldhusen <
efeldhusen.lists@gmail.com> wrote:

How would I install a non-Ruby community gem with Chef? Right now I’m
trying to use a bash script, but if there’s a way to install it with a Chef
command, I’m thinking that would make more sense.

Any suggestions?

Eric Feldhusen


#4

That is a bit different. Chef is a configuration management tool so it
wasn’t designed with the intention to build software from source. There may
be a community cookbook that would have a nice interface for you but there
are no primitive Chef resources for building RubyGems from source other
than system commands given through ‘execute’ or ‘bash’ resources.

That being said, I have tried building software from source inside a
chef-client run before and it can sometimes be a bit of a crap-shoot. I
would encourage you to use a tool designed for building Gem artifacts,
store that artifact in a repository of some kind and have Chef pull the
appropriate gem from that artifact repository.

Tom Duffield — Automation Consulting Engineer

651.769.7497 – tom@opscode.com – *my:
*Linkedinhttp://www.linkedin.com/in/thomasduffield/
Twitter https://twitter.com/tomduffield

OPSCODE

CODE CAN
opscode.com http://www.opscode.com Blog http://www.opscode.com/blog/
Facebook http://www.facebook.com/opscode
Twitterhttp://www.twitter.com/opscode
YouTube http://www.youtube.com/opscode

On Wed, Oct 30, 2013 at 8:45 AM, Eric Feldhusen
efeldhusen.lists@gmail.comwrote:

What if I needed to build the gem from source since we’re running
different versions of Ruby?

Eric Feldhusen

On Wed, Oct 30, 2013 at 9:42 AM, Tom Duffield tom@opscode.com wrote:

The gem_package resource has a source parameter where you can specify a
.gem file: http://docs.opscode.com/resource_gem_package.html

Tom Duffield — Automation Consulting Engineer

651.769.7497 – tom@opscode.com – *my: *Linkedinhttp://www.linkedin.com/in/thomasduffield/
Twitter https://twitter.com/tomduffield

OPSCODE

CODE CAN
opscode.com http://www.opscode.com Bloghttp://www.opscode.com/blog/
Facebook http://www.facebook.com/opscode Twitterhttp://www.twitter.com/opscode
YouTube http://www.youtube.com/opscode

On Wed, Oct 30, 2013 at 8:39 AM, Eric Feldhusen <
efeldhusen.lists@gmail.com> wrote:

How would I install a non-Ruby community gem with Chef? Right now I’m
trying to use a bash script, but if there’s a way to install it with a Chef
command, I’m thinking that would make more sense.

Any suggestions?

Eric Feldhusen


#5

Can you maybe leverage bundler for that?

E.g. create a ‘Gemfile’ with contents (off the top of my head, might not be
syntactically correct):
’’'
source :rubygems

gem “mygem”, “1.0”, git: “https://github.com/someone/mygem.git”, ref:
“master”
’’’

You could create the Gemfile and then shell out to ‘bundle install’ during
the Chef run

HTH, Torben
On Oct 30, 2013 2:45 PM, “Eric Feldhusen” efeldhusen.lists@gmail.com
wrote:

What if I needed to build the gem from source since we’re running
different versions of Ruby?

Eric Feldhusen

On Wed, Oct 30, 2013 at 9:42 AM, Tom Duffield tom@opscode.com wrote:

The gem_package resource has a source parameter where you can specify a
.gem file: http://docs.opscode.com/resource_gem_package.html

Tom Duffield — Automation Consulting Engineer

651.769.7497 – tom@opscode.com – *my: *Linkedinhttp://www.linkedin.com/in/thomasduffield/
Twitter https://twitter.com/tomduffield

OPSCODE

CODE CAN
opscode.com http://www.opscode.com Bloghttp://www.opscode.com/blog/
Facebook http://www.facebook.com/opscode Twitterhttp://www.twitter.com/opscode
YouTube http://www.youtube.com/opscode

On Wed, Oct 30, 2013 at 8:39 AM, Eric Feldhusen <
efeldhusen.lists@gmail.com> wrote:

How would I install a non-Ruby community gem with Chef? Right now I’m
trying to use a bash script, but if there’s a way to install it with a Chef
command, I’m thinking that would make more sense.

Any suggestions?

Eric Feldhusen


#6

If you want to build a gem from a git repository (like github), you can use
https://github.com/rdp/specific_install :
$ gem specific_install -l http://github.com/githubsvnclone/rdoc.git -b edge

I create a cookbook to do this with a LWRP (and a provider to
gem_package… but not sure it really works):
http://community.opscode.com/cookbooks/gem_specific_install

Guilhem Lettron

On Wed, Oct 30, 2013 at 5:48 PM, Torben Knerr ukio@gmx.de wrote:

Can you maybe leverage bundler for that?

E.g. create a ‘Gemfile’ with contents (off the top of my head, might not
be syntactically correct):
’’'
source :rubygems

gem “mygem”, “1.0”, git: “https://github.com/someone/mygem.git”, ref:
“master”
’’’

You could create the Gemfile and then shell out to ‘bundle install’ during
the Chef run

HTH, Torben
On Oct 30, 2013 2:45 PM, “Eric Feldhusen” efeldhusen.lists@gmail.com
wrote:

What if I needed to build the gem from source since we’re running
different versions of Ruby?

Eric Feldhusen

On Wed, Oct 30, 2013 at 9:42 AM, Tom Duffield tom@opscode.com wrote:

The gem_package resource has a source parameter where you can specify a
.gem file: http://docs.opscode.com/resource_gem_package.html

Tom Duffield — Automation Consulting Engineer

651.769.7497 – tom@opscode.com – *my: *Linkedinhttp://www.linkedin.com/in/thomasduffield/
Twitter https://twitter.com/tomduffield

OPSCODE

CODE CAN
opscode.com http://www.opscode.com Bloghttp://www.opscode.com/blog/
Facebook http://www.facebook.com/opscode Twitterhttp://www.twitter.com/opscode
YouTube http://www.youtube.com/opscode

On Wed, Oct 30, 2013 at 8:39 AM, Eric Feldhusen <
efeldhusen.lists@gmail.com> wrote:

How would I install a non-Ruby community gem with Chef? Right now I’m
trying to use a bash script, but if there’s a way to install it with a Chef
command, I’m thinking that would make more sense.

Any suggestions?

Eric Feldhusen


#7

Thanks, I’ll have to try a couple of those suggestions shortly.

Eric

On Thu, Oct 31, 2013 at 5:40 AM, Guilhem Lettron guilhem@lettron.fr wrote:

If you want to build a gem from a git repository (like github), you can
use https://github.com/rdp/specific_install :
$ gem specific_install -l http://github.com/githubsvnclone/rdoc.git -b
edge

I create a cookbook to do this with a LWRP (and a provider to
gem_package… but not sure it really works):
http://community.opscode.com/cookbooks/gem_specific_install

Guilhem Lettron

On Wed, Oct 30, 2013 at 5:48 PM, Torben Knerr ukio@gmx.de wrote:

Can you maybe leverage bundler for that?

E.g. create a ‘Gemfile’ with contents (off the top of my head, might not
be syntactically correct):
’’'
source :rubygems

gem “mygem”, “1.0”, git: “https://github.com/someone/mygem.git”, ref:
“master”
’’’

You could create the Gemfile and then shell out to 'bundle install’
during the Chef run

HTH, Torben
On Oct 30, 2013 2:45 PM, “Eric Feldhusen” efeldhusen.lists@gmail.com
wrote:

What if I needed to build the gem from source since we’re running
different versions of Ruby?

Eric Feldhusen

On Wed, Oct 30, 2013 at 9:42 AM, Tom Duffield tom@opscode.com wrote:

The gem_package resource has a source parameter where you can specify a
.gem file: http://docs.opscode.com/resource_gem_package.html

Tom Duffield — Automation Consulting Engineer

651.769.7497 – tom@opscode.com – *my: *Linkedinhttp://www.linkedin.com/in/thomasduffield/
Twitter https://twitter.com/tomduffield

OPSCODE

CODE CAN
opscode.com http://www.opscode.com Bloghttp://www.opscode.com/blog/
Facebook http://www.facebook.com/opscode Twitterhttp://www.twitter.com/opscode
YouTube http://www.youtube.com/opscode

On Wed, Oct 30, 2013 at 8:39 AM, Eric Feldhusen <
efeldhusen.lists@gmail.com> wrote:

How would I install a non-Ruby community gem with Chef? Right now I’m
trying to use a bash script, but if there’s a way to install it with a Chef
command, I’m thinking that would make more sense.

Any suggestions?

Eric Feldhusen


#8

A little late to this party, but if you’re running your own gem source
already you might as well take a look at precompiling the native extensions
on your target platform(s) and pushing them to your repo. You would
obviously not want to do this in your deployment recipe but instead make
it part of a CI job.

This stack overflow link might help point you in the right direction.

http://stackoverflow.com/questions/3667918/how-do-you-precompile-the-native-extensions-for-a-ruby-gem-for-linux

You’d be okay installing via chef_gem or gem_package at that point in your
recipe.

Disclaimer: I haven’t done all this myself in a Chef recipe lately, but I
did it a while back in a “compilers-in-prod-ist-verboten!” environment with
Puppet and it worked then.

On Thu, Oct 31, 2013 at 11:01 AM, Eric Feldhusen <efeldhusen.lists@gmail.com

wrote:

Thanks, I’ll have to try a couple of those suggestions shortly.

Eric

On Thu, Oct 31, 2013 at 5:40 AM, Guilhem Lettron guilhem@lettron.frwrote:

If you want to build a gem from a git repository (like github), you can
use https://github.com/rdp/specific_install :
$ gem specific_install -l http://github.com/githubsvnclone/rdoc.git -b
edge

I create a cookbook to do this with a LWRP (and a provider to
gem_package… but not sure it really works):
http://community.opscode.com/cookbooks/gem_specific_install

Guilhem Lettron

On Wed, Oct 30, 2013 at 5:48 PM, Torben Knerr ukio@gmx.de wrote:

Can you maybe leverage bundler for that?

E.g. create a ‘Gemfile’ with contents (off the top of my head, might not
be syntactically correct):
’’'
source :rubygems

gem “mygem”, “1.0”, git: “https://github.com/someone/mygem.git”, ref:
“master”
’’’

You could create the Gemfile and then shell out to 'bundle install’
during the Chef run

HTH, Torben
On Oct 30, 2013 2:45 PM, “Eric Feldhusen” efeldhusen.lists@gmail.com
wrote:

What if I needed to build the gem from source since we’re running
different versions of Ruby?

Eric Feldhusen

On Wed, Oct 30, 2013 at 9:42 AM, Tom Duffield tom@opscode.com wrote:

The gem_package resource has a source parameter where you can specify
a .gem file: http://docs.opscode.com/resource_gem_package.html

Tom Duffield — Automation Consulting Engineer

651.769.7497 – tom@opscode.com – *my: *Linkedinhttp://www.linkedin.com/in/thomasduffield/
Twitter https://twitter.com/tomduffield

OPSCODE

CODE CAN
opscode.com http://www.opscode.com Bloghttp://www.opscode.com/blog/
Facebook http://www.facebook.com/opscode Twitterhttp://www.twitter.com/opscode
YouTube http://www.youtube.com/opscode

On Wed, Oct 30, 2013 at 8:39 AM, Eric Feldhusen <
efeldhusen.lists@gmail.com> wrote:

How would I install a non-Ruby community gem with Chef? Right now
I’m trying to use a bash script, but if there’s a way to install it with a
Chef command, I’m thinking that would make more sense.

Any suggestions?

Eric Feldhusen