- From: Daniel DeLeo <
>
- To:
- Subject: [chef] Re: Access a Node's Previous Attributes
- Date: Fri, 27 Jun 2014 09:49:59 -0700
On Friday, June 27, 2014 at 9:15 AM,
wrote:
>
Hi everyone,
>
>
I was wondering if Chef's current API allows me to have access to my node's
>
previous attributes (i.e. before downloading/converging new
>
roles/environments/cookbooks)? I tried this out using
>
'Chef::Node.load(..)[my_attribute]' which worked giving me the value of the
>
attribute from the last chef run.
>
>
I feel like this could greatly simplify a lot of cookbooks I have written by
>
providing me the 'current' state of the node vs what it should be.
>
Specifically
>
this could help me with,
This is possible, but I think it’s better to use the host system as the
source of truth if possible.
>
>
* Determine if we should upgrade our application (i.e. did the version
>
change)
Depending on how you ship your app, you should be able to get this from the
package system, a VERSION.txt file, git, `command —version` or something like
that. If your app doesn’t have any way of determining the current version,
you should work with the app developers to make this a possibility.
>
* We have an attribute that is an array of URLs to files which we should
>
download and put in our app's lib directory. We could use the previous
>
value to
>
determine which URLs were removed and remove those files.
You should be able to do this by comparing the directory contents to the
array.
>
>
Bryan
Generally you’ll be better off if you examine the actual system to determine
the current state. There’s all sorts of ways external data can drift from the
actual reality, such as:
* Configuration done outside of chef-client (administrator, another script or
process, etc.)
* chef-client partially configures a machine and then fails on a later step
(in which case the node attributes from the current run won’t be saved)
HTH,
--
Daniel DeLeo
Archive powered by MHonArc 2.6.16.