Search code examples
chef-infrachef-recipe

How to include a chef recipe based on the output from bash command?


I would like to get the count of a particular process , and include the config recipe only if there are no processes.

Something to this effect. How is this possible in chef?

if !( "(ps aux | grep splunkd | grep -v grep | wc -l) > 0 ") 
  include_recipe 'platform::splunk_config' 
end

Solution

  • i can offer an idea to use ruby_block resourece in a conjunction with a guard, and it should be something like:

    ruby_block 'splank configuration' do
      block { include_recipe 'platform::splunk_config' }
      not_if "ps aux | grep splunkd | grep -v grep | wc -l > 0"
    end
    

    but i haven't tried it :)