[chef] Re: Re: Determining if a chef-client run is an initial chef-client run through handlers


Chronological Thread 
  • From: Roger Lam < >
  • To:
  • Subject: [chef] Re: Re: Determining if a chef-client run is an initial chef-client run through handlers
  • Date: Wed, 4 Mar 2015 11:36:54 -0800

Double reply to myself incoming.

Found a way with chef tags! Wish it came to me earlier.

if tagged?('initial_chef_run')
  untag('initial_chef_run')
  tag('subsequent_chef_run')
elsif !tagged?('subsequent_chef_run')
  tag('initial_chef_run')
end

And check if it's tagged as an initial chef run in the handler.

initial_chef_run = node.tags.include?('initial_chef_run')

Inspiration from this post:
http://sysadvent.blogspot.com/2012/12/day-24-twelve-things-you-didnt-know.html#item_12

On Tue, Mar 3, 2015 at 4:53 PM, Roger Lam 
< >
 wrote:
> Hi Mike and Chefs,
>
> I found the 'registration_completed' method under the EventDispatch class.
> http://www.rubydoc.info/github/chef/chef/master/Chef/EventDispatch/Base:registration_completed
>
> There's a section in the Customizing Chef book that overrides event
> methods and injects them with start handlers but that's not exactly
> what I'm looking for. Ideally, the code would live in a single
> cookbook and not spread to the client.rb or a separate gem as start
> handlers require.
>
> I'd love and really appreciate any ideas. Thanks!
>
> Roger
>
>
> On Tue, Feb 24, 2015 at 10:08 AM, Roger Lam 
> < >
>  wrote:
>> Great idea! I'll give it a shot. Thank you Mike!
>>
>> On Tue, Feb 24, 2015 at 6:33 AM, Michael Glenney 
>> < >
>>  wrote:
>>> While looking at resource counts would probably be mostly accurate 
>>> (initial
>>> chef runs don't update 100% of resources but usually way more than 
>>> re-runs)
>>> it would be problematic.
>>>
>>> I would tap the 'registration_completed' handler method:
>>>
>>>       def registration_completed
>>>       end
>>>
>>> This isn't necessarily going to be 100% accurate either but it should be
>>> "more" accurate.   An example of it not being accurate would be a node 
>>> that
>>> was deleted from the chef server so it needs to reregister itself.  Not an
>>> "initial" run but would trigger this.  I think this is an edge case though
>>> as you generally wouldn't keep the validation pem around on an existing 
>>> node
>>> so this wouldn't happen without you knowing about it.
>>>
>>> Mike Glenney
>>> New Context
>>>
>>> On Mon, Feb 23, 2015 at 11:42 PM, Roger Lam 
>>> < >
>>>  wrote:
>>>>
>>>> Hi,
>>>>
>>>> I'm trying to count the number of initial chef-client runs through
>>>> handlers and my initial idea was to compare the number updated
>>>> resources with the total number of resources and if they're equal,
>>>> then it's an initial run. However, this is not the case most of the
>>>> time. Has anyone found a way to do this?
>>>> Thank you!
>>>>
>>>> Roger
>>>
>>>



Archive powered by MHonArc 2.6.16.

§