[chef] Re: Re: Re: Re: Re: Add Client to Chef Server Immediately?


Chronological Thread 
  • From: Lamont Granquist < >
  • To:
  • Cc: Daniel DeLeo < >
  • Subject: [chef] Re: Re: Re: Re: Re: Add Client to Chef Server Immediately?
  • Date: Tue, 12 Aug 2014 16:40:51 -0700

On Tue Aug 12 15:54:56 2014, Daniel DeLeo wrote:


On Tuesday, August 12, 2014 at 3:38 PM, Douglas Garstang wrote:

Daniel,

Caveats aside, where would the node.save go? Would it go in the recipe 
somewhere very early in the run list? I think the hack I saw had this run on 
the client side with chef-client.

Doug.
Yeah, you can put it in a recipe, probably at the top-level (i.e., not in a 
ruby_block resource) so it’ll run during the compile phase. If you’re using a 
Chef Server with the older Solr (most likely if you’re not on Hosted 
Enterprise Chef) then the next commit should happen within 60 seconds 
(assuming you haven’t changed the default tuning). So you have to either 
sleep 60 or poll search until the node can find itself. If you opt for 
polling, make sure you have sufficient wait time in between checks or else 
you can kill the server performance in some situations (e.g., you bring up a 
new test environment with a bunch of brand new nodes and they’re all 
hammering the server).

--
Daniel DeLeo


Something along these lines...

# hack to update run list in the database so we can search and find ourselves later
node.save

wordpress_nodes = nil
tries = 50
loop do
 Chef::Log.info("Searching for wordpress nodes...")
wordpress_nodes = search(:node, "role:wordpress AND chef_environment:#{node.chef_environment}")
 break unless wordpress_nodes.empty?
 break unless ( tries -= 1 ) < 0
Chef::Log.info("Found zero nodes in #{node.chef_environment} environment, retrying (left: #{tries})")
 sleep 2
end

Of course the obvious bug there is that if you've already got nodes in your environment it'll find those and you wont find yourself because of the race between the node.save and the results showing up in solr. You could instead loop until you got results containing yourself or something if you always expect to get yourself to show up. Of course then its probably better to just combine the node data you have with the search results you get back and avoid worrying about the round trip to solr just to get your own node data back.




Archive powered by MHonArc 2.6.16.

§