Trying to create links to installed package

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

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

Thank you for the help.

Is there a philosophical reason why specifying the version number is the better answer? Tying your recipe to a specific version of a package requires more maintenance. If Chef provided a way to detect the version number of the package it just installed, the recipe could be more generic.

From: Daniel DeLeo [mailto:ddeleo@kallistec.com] On Behalf Of Daniel DeLeo
Sent: Monday, October 21, 2013 10:49 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Trying to create links to installed package

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

On Monday, October 21, 2013 at 4:15 PM, THARP, JOSHUA L wrote:

Thank you for the help.

Is there a philosophical reason why specifying the version number is the better answer? Tying your recipe to a specific version of a package requires more maintenance. If Chef provided a way to detect the version number of the package it just installed, the recipe could be more generic.

If you specify the version number in the recipe, then all of your logic is in one place and you’re driving all of your configuration from one piece of data. This is easy to extend to a case where, say, you have multiple versions of the package in the repo and you want to try out the new version in a test/preprod/staging environment before you start using it in production.

In your current setup, you have moved some config info into your package repo, and it’s driven by logic you don’t control (namely, the sorting rules for package versions).

--
Daniel DeLeo