I have the following (simplified) recipe called java, to install Java of course.
File recipes/default.rb
include_recipe \"install_java\"
The best thing to do is write a custom resource using unified_mode, instead of a recipe:
resources/install_java.rb:
unified_mode true
provides :install_java
action :install do
# Install RPM from yum repo via yum_install library function
yum_install("jdk1.7.0_51")
# List the directories in /usr/java
jdk_dir = `ls -ld /usr/java/jdk1.* | sort | tail -1`
if jdk_dir.empty?
raise "Missing JDK installation"
end
end
recipes/default.rb:
install_java "install my java -- you could make this name_property the version"
Unified mode eliminates the compile/converge two-phase parsing so that this works, but the code must be moved to a custom resource (which confers additional usability benefits and is a best practice anyway -- now the resource can grow properties and can be reused to install different versions of java, etc).