[chef] Re: Trying to create links to installed package


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: Trying to create links to installed package
  • Date: Mon, 21 Oct 2013 10:49:26 -0700


On Monday, October 21, 2013 at 6:43 AM, THARP, JOSHUA L wrote:

I’m writing a cookbook for a locally-built package served by a local yum server. The installation is straight-forward enough.

 

package “my-package”

 

Now I am creating a second recipe that creates links to the installed package. However, the package installation directory contains the version number of the package. Is there a way to capture either the directory created by the package command or the version of the package installed?

 

My target platform is a Fedora-based Linux so I can use yum_package if that helps solve this issue.

 

My attempts to solve this:

ver = `yum list my-package | grep “my-package” | cut –c 41-55`.strip

ver = `yum info my-package | grep “my-package” | cut –f 3 –d ‘-‘

both return nothing on the first chef-client run (broken links) and return the correct value on the second chef-client run (fixed links). Also neither will work if more than one version of my-package is on the box.

 

Suggestions?

 

Thanks,

 

Josh

A few ways to do this:

The best way is if you know the version number up front:

package "thing" do
  version node[:my_package][:version]
end

link "/bin/thing" do
  to "/opt/my_package/#{node[:my_package][:version]}/bin/thing"
end

If that's completely unpossible for you, then you need to use a little bit of magic to get the link path during the converge phase, e.g.

link "/bin/thing" do

  # create a lazy resource attribute that will find the path:
  path_finder = lazy do
    version = ver = `yum list my-package | grep “my-package” | cut –c 41-55`.strip
    "/opt/my_package/#{version}/bin/thing"
  end

  # set the `to` attribute of the link resource to the lazy-evaluated attribute
  to path_finder
end

-- 
Daniel DeLeo




Archive powered by MHonArc 2.6.16.

§