Reputation: 241
I would like to query he YUM repo before I call the install block to make sure the pkg is available
I am using the following code at the beginning of my recipee
ruby_block 'shellout' do
block do
cmd = Mixlib::ShellOut.new('yum search httpd | grep -w httpd.x86_64 |tr -d "\n\r"'
cmd.run_command
Chef::Log.warn("printing #{cmd.stdout}")
if cmd.stdout =~ /httpd/i
Chef::Log.warn("pkg found in yum #{cmd.stdout}")
elsif cmd.stdout =~ /error/i
Chef::Log.warn("yum returned an error #{cmd.stdout}")
else
Chef::Log.warn("pkg not in repo ? yum search returns #{cmd.stdout}")
end
end
end
however despite the fact that the pkg is in the repo the code does not work.
1) What am I doing wrong ?
2) Is there an easier way to do this ?
3) If the answer is "because your code is not running at run time how do I force it to run at Cf's run time ?
thanks
Upvotes: 0
Views: 102
Reputation: 54249
This is not really how Chef works. You don't react to system state, you declared what it should be and then Chef enforces that. Way down in the depths it does the test-and-repair loop but high level, if the package should be installed then use a package
resource. If you need to set up a specific repo first, we have the yum_repository
resource. If this should be configurable per-host (or per-role, which is better) maybe use a node attribute to make the whole section conditional.
Upvotes: 1