[chef] Re: Re: proper example of state attributes?


Chronological Thread 
  • From: Medya < >
  • To:
  • Subject: [chef] Re: Re: proper example of state attributes?
  • Date: Thu, 19 Feb 2015 20:36:29 -0600

Thanks for the reply Daniel,

but cant I have the same effect with normal attributes?
like the case of the package, if I run action install on a package, I can change the a normal attribute to the version of the installed version ?  why do I have to declare it as state attribute?

and another question ,
how can I access a state attribute ? can I access them through node objects ? are they stored on the chef server or on the client side ?



On Thu, Feb 19, 2015 at 5:21 PM, Daniel DeLeo < " target="_blank"> > wrote:


On Thursday, February 19, 2015 at 2:45 PM, Medya wrote:

> can someone explain me difference of normal attributes in lwrp with state attributes and a good example ?
>
> I have not used state attribute yet, but my assumption is its supposed to be reflexing the current state ? how is that diffrent with normal attribute , both of them can be accessed outside and both can be changed if you want to ...

State attributes just declare which attributes in a resource actually describe the state of the underlying system. Consider for example, a package resource. It has a package name and a version. Installing a package changes the state of the version from “null” (not installed) to some version number. Upgrading and downgrading change the version from one version number to a different version number. The package resource has bunch of other attributes that don’t describe the actual desired state of the system but instead give Chef hints about how to transition from one state to another. For example, the timeout attribute tells Chef how long it should wait before assuming a package install operation got stuck. But whether the timeout is 5 seconds or 5 hours has nothing to do with the package’s state. There are lots of other examples, such as customizing the start and stop commands of a service, the atomic update stuff for files, and so on; all of these only tell chef how to change your system from one state to another, but do not describe the state of the system.

The list of state attributes is used by the reporting system in Chef (1) so that only meaningful information about system changes is sent to the reporting service (which is a paid add-on to the server, though there are free alternatives like foreman that re-use the client code).

Note also that the identity attribute has a similar function, it says which attribute of a resource uniquely identifies the actual thing on the system it represents. For a file, it’s the path, for package it’s the name, etc.

HTH

--
Daniel DeLeo

1. https://github.com/chef/chef/blob/b69b4efc17c6a34a43df6265d02a624fe2e8dd14/lib/chef/resource_reporter.rb#L93-L98




Archive powered by MHonArc 2.6.16.

§