We are setting up a cluster using Apache Ambari.
Our Chef run is interrupted by the need to use Ambari to provision the Hadoop cluster. Current installs are a three part process:
- Initial Chef run to prep OS.
- Use Ambari to configure (and later manage) Hadoop cluster.
- Post-Ambari configs using a second Chef run.
I searched similar questions, but answers all revolved around using resources that included guard attributes for conditionals. The second run uses a series of resources that do not accept guard attributes.
I've been working around this by using execute commands and "not_if"/"only_if" guards. Example:
%w{package1 package2 package3 package4}.each do |package|
execute "Install #{package}" do
command "yum install #{package}"
user 'root'
only_if { ::File.exists?("/etc/yum.repos.d/ambari.repo")}
end
end
But this gets tedious to write for each resource. There has got to be a better way.
Is there a standard or "best" practice for executing all remaining code (or select resources) in a recipe if one conditional is met?
I thought about wrapping in a Ruby block and using notifies, but blocks seem declarative. I'm not sure how best to set them up to "do x if y, else nothing", or even if that's the right tool for the job?
ruby_block "Check for Ambari.repo" do
block do
File.exists?("/etc/yum.repos.d/ambari.repo")
end
notifies :run "execute[package]" :immediately
end
%w{package1 package2 package3 package4}.each do |package|
execute "Install #{package}" do
command "yum install #{package}"
user 'root'
action :nothing
end
end