Installing a gem after native extension packages during chef execution
Asked Answered
S

2

5

I am trying to install the fog gem in a chef recipe though the gem installation occurs before the native packages are being installed so the gem installation fails

package "libxslt-dev"
package "libxml2-dev"

chef_gem "fog"

This is the output

[Thu, 14 Mar 2013 13:04:30 +0000] INFO: Processing chef_gem[fog] action install (ebs4000::update_volumes line 23)
[Thu, 14 Mar 2013 13:04:52 +0000] ERROR: Running exception handlers
[Thu, 14 Mar 2013 13:04:52 +0000] FATAL: Saving node information to /var/cache/chef/failed-run-data.json
[Thu, 14 Mar 2013 13:04:52 +0000] ERROR: Exception handlers complete
[Thu, 14 Mar 2013 13:04:52 +0000] ERROR: Gem::Installer::ExtensionBuildError: chef_gem[fog] (cookbook::recipe line 4) had an error: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.8 extconf.rb
checking for libxml/parser.h... no
-----
libxml2 is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    ...
    --with-pkg-config
    --without-pkg-config


Gem files will remain installed in /var/lib/gems/1.8/gems/nokogiri-1.5.6 for inspection.
Results logged to /var/lib/gems/1.8/gems/nokogiri-1.5.6/ext/nokogiri/gem_make.out

I am aware of the notifies attribute of the chef resources but still can get this run properly.

So how can I actually force the execution order to first install the native packages and then the gem in the same run.

Note: Manual installation of the packages is not an option, since we want that to be fully automated for new nodes.

Spendthrift answered 14/3, 2013 at 13:20 Comment(0)
S
7

Why not try installing the dependencies at the start of the resource collection phase, as mentioned here: OPSCODE wiki: Run Resources from the Resource Collection

So your recipe would look like:

xsltdev = package "libxslt-dev" do
   action :nothing
end

xmldev = package "libxml2-dev" do
   action :nothing
end

xsltdev.run_action(:install)
xmldev.run_action(:install)

chef_gem "fog"
Sewage answered 14/3, 2013 at 20:8 Comment(1)
You can also install a list of packages with: %w{libxslt-dev libxml2-dev}.each do |pkg| p = package pkg do action :nothing end p.run_action(:install) endPaganism
H
0

It seems like you're already doing that. Recipes are executed in order, so you should be good.

In your logs, you're only showing what happened from the point where Chef tries to install fog. Have you verified that the lib packages' install are not coming up before that? You might have gotten the package names wrong, or you need to update the package manager's cache before.

Heins answered 15/3, 2013 at 2:23 Comment(1)
I didn't include the log prior to that because the package commands are not run yet. For me it looks like the gem is being installed in the resource collection phase while the package installation on the execution phase which comes after that, so this is why the problem occurs IMHO.Spendthrift

© 2022 - 2024 — McMap. All rights reserved.