What is the difference between the following following 2 gem installation methods?

What is the difference between the following following 2 gem installation methods?

gem_package "mysql" do
  action :install
end

and

r = gem_package "right_aws" do
  version node['aws']['right_aws_version']
  action :nothing
end

r.run_action(:install)

require 'rubygems'
Gem.clear_paths
require 'right_aws'

@millisami
~ Sachin Sagar Rai
Ruby on Rails Developer
http://tfm.com.np
http://nepalonrails.tumblr.com
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

the first one is triggered during execution stage, while the second one
triggers in compilation stage. Compilation happens before execution. So,
you can use the gem in all your chef resources if you trigger the gem
installation via second method.
read more here:
http://wiki.opscode.com/display/chef/Anatomy+of+a+Chef+Run

regards
ranjib

On Thu, Mar 8, 2012 at 3:13 PM, Sachin Sagar Rai millisami@gmail.comwrote:

What is the difference between the following following 2 gem
installation methods?

gem_package "mysql" do
  action :install
end

and

r = gem_package "right_aws" do
  version node['aws']['right_aws_version']
  action :nothing
end

r.run_action(:install)

require 'rubygems'
Gem.clear_paths
require 'right_aws'

@millisami
~ Sachin Sagar Rai
Ruby on Rails Developer
http://tfm.com.np
http://nepalonrails.tumblr.com
Sent with Sparrow http://www.sparrowmailapp.com/?sig

On Thu, Mar 8, 2012 at 4:43 AM, Sachin Sagar Rai millisami@gmail.com wrote:

What is the difference between the following following 2 gem installation
methods?

gem_package "mysql" do
  action :install
end

This is used to install a gem to your system, such as when you're
installing a Ruby application to run as a service.

r = gem_package "right_aws" do
  version node['aws']['right_aws_version']
  action :nothing
end

r.run_action(:install)

require 'rubygems'
Gem.clear_paths

This is used to install a gem immediately so you can use the gem in a
Chef recipe. In Chef 0.10.10+ this will be replaced by:

chef_gem "right_aws" do
version node['aws']['right_aws_version']
end

http://tickets.opscode.com/browse/CHEF-2879

Bryan

Thanks Guys! for clarifying.

Is there any way to make the gem installation conditional? Like only_if ? So that the chef-client doesn't install those gems in each run?


@millisami
~ Sachin Sagar Rai
Ruby on Rails Developer
http://tfm.com.np
http://nepalonrails.tumblr.com
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Thursday, March 8, 2012 at 8:23 PM, Bryan McLellan wrote:

On Thu, Mar 8, 2012 at 4:43 AM, Sachin Sagar Rai <millisami@gmail.com (mailto:millisami@gmail.com)> wrote:

What is the difference between the following following 2 gem installation
methods?

gem_package "mysql" do
  action :install
end

This is used to install a gem to your system, such as when you're
installing a Ruby application to run as a service.

r = gem_package "right_aws" do
  version node['aws']['right_aws_version']
  action :nothing
end

r.run_action(:install)

require 'rubygems'
Gem.clear_paths

This is used to install a gem immediately so you can use the gem in a
Chef recipe. In Chef 0.10.10+ this will be replaced by:

chef_gem "right_aws" do
version node['aws']['right_aws_version']
end

http://tickets.opscode.com/browse/CHEF-2879

Bryan

In the compilation phase, you can just use the Ruby language directly.

def should_install_right_aws?
  # your custom logic here...
end

r = gem_package "right_aws" do
  version node['aws']['right_aws_version']
  action :nothing
end

r.run_action(:install) if should_install_right_aws?

Best,

Jeremy Voorhis

On Mar 8, 2012, at 2:44 PM, Sachin Sagar Rai wrote:

Thanks Guys! for clarifying.

Is there any way to make the gem installation conditional? Like only_if ? So that the chef-client doesn't install those gems in each run?


@millisami
~ Sachin Sagar Rai
Ruby on Rails Developer
http://tfm.com.np
http://nepalonrails.tumblr.com
Sent with Sparrow

On Thursday, March 8, 2012 at 8:23 PM, Bryan McLellan wrote:

On Thu, Mar 8, 2012 at 4:43 AM, Sachin Sagar Rai millisami@gmail.com wrote:

What is the difference between the following following 2 gem installation
methods?

gem_package "mysql" do
  action :install
end

This is used to install a gem to your system, such as when you're
installing a Ruby application to run as a service.

r = gem_package "right_aws" do
  version node['aws']['right_aws_version']
  action :nothing
end

r.run_action(:install)

require 'rubygems'
Gem.clear_paths

This is used to install a gem immediately so you can use the gem in a
Chef recipe. In Chef 0.10.10+ this will be replaced by:

chef_gem "right_aws" do
version node['aws']['right_aws_version']
end

http://tickets.opscode.com/browse/CHEF-2879

Bryan

The provider is idempotent and will not attempt to install the gem if it is installed.

On Mar 8, 2012, at 7:44, Sachin Sagar Rai millisami@gmail.com wrote:

Thanks Guys! for clarifying.

Is there any way to make the gem installation conditional? Like only_if ? So that the chef-client doesn't install those gems in each run?


@millisami
~ Sachin Sagar Rai
Ruby on Rails Developer
http://tfm.com.np
http://nepalonrails.tumblr.com
Sent with Sparrow

On Thursday, March 8, 2012 at 8:23 PM, Bryan McLellan wrote:

On Thu, Mar 8, 2012 at 4:43 AM, Sachin Sagar Rai millisami@gmail.com wrote:

What is the difference between the following following 2 gem installation
methods?

gem_package "mysql" do
  action :install
end

This is used to install a gem to your system, such as when you're
installing a Ruby application to run as a service.

r = gem_package "right_aws" do
  version node['aws']['right_aws_version']
  action :nothing
end

r.run_action(:install)

require 'rubygems'
Gem.clear_paths

This is used to install a gem immediately so you can use the gem in a
Chef recipe. In Chef 0.10.10+ this will be replaced by:

chef_gem "right_aws" do
version node['aws']['right_aws_version']
end

http://tickets.opscode.com/browse/CHEF-2879

Bryan

In a scenario where you use the following approach to make a gem
available immediately:

r = gem_package "right_aws" do
  version node['aws']['right_aws_version']
  action :nothing
end

r.run_action(:install)

Is there an established way to execute include_recipe before? I'm
running into a situation where the gem I want available immediately needs
packages for compiling native extensions. I'd like include_recipe "build-essential" to execute first.

Right now I'm using something like this to replicate the build-essential
cookbook:

fog_dependencies.each do |fog_dependency|
  d = package fog_dependency do
    action :nothing
  end

  d.run_action(:install)
end

--
Hector

On Mon, Mar 12, 2012 at 01:11, Joshua Timberman joshua@opscode.com wrote:

The provider is idempotent and will not attempt to install the gem if it
is installed.

On Mar 8, 2012, at 7:44, Sachin Sagar Rai millisami@gmail.com wrote:

Thanks Guys! for clarifying.

Is there any way to make the gem installation conditional? Like only_if
? So that the chef-client doesn't install those gems in each run?


@millisami
~ Sachin Sagar Rai
Ruby on Rails Developer
http://tfm.com.np
http://nepalonrails.tumblr.com
Sent with Sparrow http://www.sparrowmailapp.com/?sig

On Thursday, March 8, 2012 at 8:23 PM, Bryan McLellan wrote:

On Thu, Mar 8, 2012 at 4:43 AM, Sachin Sagar Rai millisami@gmail.com
wrote:

What is the difference between the following following 2 gem installation
methods?

gem_package "mysql" do
  action :install
end

This is used to install a gem to your system, such as when you're
installing a Ruby application to run as a service.

r = gem_package "right_aws" do
  version node['aws']['right_aws_version']
  action :nothing
end

r.run_action(:install)

require 'rubygems'
Gem.clear_paths

This is used to install a gem immediately so you can use the gem in a
Chef recipe. In Chef 0.10.10+ this will be replaced by:

chef_gem "right_aws" do
version node['aws']['right_aws_version']
end

http://tickets.opscode.com/browse/CHEF-2879

Bryan