[chef] Re: Re: Re: Re: Re: Re: Re: knife search'ing for an inherited recipe?


Chronological Thread 
  • From: Jek Sirex < >
  • To:
  • Subject: [chef] Re: Re: Re: Re: Re: Re: Re: knife search'ing for an inherited recipe?
  • Date: Fri, 18 Oct 2013 12:35:52 +0300

For certain cookbook I'm using attributes as marker. If I have, for example gmond recipe (ganglia monitor daemon) I'm setting node.ganglia.recipe.gmond true. And search for this.
But, hardcoded search is bad practice: somebody uses roles, somebody wrapper-cookbook or library. 
That's why new best practice for me is using search_query_attribute. I'll actually be able overwrite it in role, cookbook, node attributes, etc. Works fine for me.
Real use case: nagios cookbook. I can't use it because I haven't roles and use wrapper. For me it is:
* no host groups
* no search

Next step of evolution is move search attributes from attributes folder to helper recipe "_search_attributes.rb". This change incorporate new ability to use overridden attributes from wrapped cookbook.
Use Case:

query = []
query << "chef_environment:#{node.chef_environment}"
query << "my_custom_attribute_one:#{node.my.attr.one}"
query << "my_custom_attribute_two:#{node.my.attr.two}"
node.default['myrecipe']['search']['entity'] = query.join(' AND ')

If this code located in attributes folder it evaluates at very begin of chef run and I can't override attributes from other cookbooks. Moving to recipe gives me possibility to override only one attribute:
node.override.my.attr.two = "different attr"
include_recipe "myrecipe" # which actually the includes _search_attributes.rb recipe and will use new value

If you have very different environment you still able to override whole search query as you need:
node.override.myrecipe.search.entity = "recipe:my-wrapper"

Cookbook sample of ganglia: https://github.com/jsirex/cookbook-ganglia


2013/10/18 Ranjib Dey < " target="_blank"> >
theres no direct way, at pagerduty we use a handler , pd-chef-handler to do this. it stores run_status.run_context.loaded_recipes.uniq as a node attribute (node.chef_client.metrics). this, will always contain all the included recipes for a successfully converged node. but i think its a bad to search against recipes that are not top level (i.e part of a role or directly inside the run_list),


On Thu, Oct 17, 2013 at 9:44 PM, DV < " target="_blank"> > wrote:
Any idea how to search for recipes that were inherited due to include_recipe?


On Mon, Oct 14, 2013 at 2:05 PM, Guy Matz < " target="_blank"> > wrote:
Sweet!!!


On Mon, Oct 14, 2013 at 4:40 PM, Ranjib Dey < " target="_blank"> > wrote:
just do `knife search node "recipes:foo"`,

chef stores all the recipes (defined in run_list directly or via roles) into an attribute named "recipes", as part of the run list expansion., hence you can search the recipes (as well as roles) attribute, they are top level node attributes



On Mon, Oct 14, 2013 at 1:34 PM, Guy Matz < " target="_blank"> > wrote:
No, that didn't do the trick, if I understood you correctly:
/]$ knife search node 'run_list:recipes\[bondage\:\:dns\]'
0 items found

however:
/]$ knife search node 'role:iad-web' | grep bondage::dns | wc -l
11
/]$ knife search node 'role:auto-bonded' | grep bondage::dns | wc -l
18
/]$ knife search node 'role:auto-bonded' | head
18 items found

Node Name:   iad-hadoop105.ihr
Environment: _default
FQDN:        iad-hadoop105.ihr
IP:          10.5.40.169
Run List:    role[base], role[hadoop], role[auto-bonded]
Roles:       sendmail-smart-host, auto-bonded, base, hadoop
Recipes:     resolver, yum, ntp, timezone, cron, chef-client, zsh, users::sysadmins, sudo, emacs, vim, git, build-essential, perl, python, screen, nscd, openssh, motd-tail, operations, logrotate::syslog, vmware-tools::noop, sendmail, sendmail::sendmail_smart_host, users::hadoop, bondage::dns
Platform:    centos 6.3

Thanks again!


On Mon, Oct 14, 2013 at 4:21 PM, Daniel DeLeo < " target="_blank"> > wrote:

On Monday, October 14, 2013 at 1:19 PM, Guy Matz wrote:

Hi!  Is there a way to "knife search node" for all of the nodes that have a specific recipe, regardless of which role has included the recipe in the run_list?

I have a recipe called bondage::dns that is in a few roles . . .  I've tried this, but it didn't work:
knife search node 'run_list:recipe\[bondage\:\:dns\]'

Any help would be greatly appreciated!

Thanks,
Guy
search for `recipes` with an 's'. This won't pick up recipes that get run via `include_recipe`, though.

-- 
Daniel DeLeo







--
Best regards, Dmitriy V.





Archive powered by MHonArc 2.6.16.

§