Using chef
I have a simple recipe that installs a gem, example:
gem_package "passenger" do
version node['passenger']['version']
end
I also want to install ruby with another cookbook, it might be Ruby 1.9.3 for some servers and Ruby Enterprise 1.8.7 for others. So I thought I could use gem_binary
and ohai
to do this, like this:
gem_package "passenger" do
version node['passenger']['version']
gem_binary "#{languages['ruby']['bin_dir']/gem}"
end
But then the problems start, because languages['ruby']
is not changed when a new ruby is installed. Ruby Enterprise installs into /opt/ruby-enterprise
and adds itself to PATH
via /etc/profile.d/ree.sh
but that is not being picked up by ohai
during the same run, but gets picked up in the next run.
In the first run, ohai
says that languages['ruby']
is installed in /opt/vagrant_ruby/bin/ruby
when used with vagrant
and chef_solo
provision. And the passenger gem is installed into the wrong ruby.
How can I make ohai
recognize the newly installed ruby?
Usually I am working with RVM which has the same problem. There I usually hardcode the path to the gem binary and leave the last bit as an attribute.
E.G.
something like
5 node["rvm"]["rubies"].each do |ruby|
6 gem_package "[#{ruby}]-passenger" do
7 package_name "passenger"
8 version node[:passenger][:version]
9 gem_binary "/usr/local/rvm/bin/gem-#{ruby}"
10 options "--no-ri --no-rdoc"
11 end
12 end
Alternatively we have used bash
blocks and sourced the appropriate file. Note when using bash blocks only the last thing in the block will be used to determine success, it is often wise to chain them with &&
I think there's a way to reload ohai attributes during running chef recipe:
You need to use ohai resource:
ohai "reload" do
action :reload
end
See more here: http://wiki.opscode.com/display/chef/Resources#Resources-Ohai
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With