# Access a Node's Previous Attributes

**URL:** <https://discourse.chef.io/t/access-a-nodes-previous-attributes/5469>\
**Category:** Chef Infra (archive)\
**Created:** [June 27, 2014, 4:15pm UTC](https://discourse.chef.io/t/access-a-nodes-previous-attributes/5469 "2014-06-27T16:15:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbaugher](https://avatars.discourse-cdn.com/v4/letter/b/97f17d/32.png) [@bbaugher](https://discourse.chef.io/u/bbaugher)\
**Post date:** [June 27, 2014, 4:15pm UTC](https://discourse.chef.io/t/access-a-nodes-previous-attributes/5469/1 "2014-06-27T16:15:13Z")

</div>

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,

- Determine if we should upgrade our application (i.e. did the version change)
- 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.

Bryan

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [June 27, 2014, 4:49pm UTC](https://discourse.chef.io/t/access-a-nodes-previous-attributes/5469/2 "2014-06-27T16:49:59Z")

</div>

On Friday, June 27, 2014 at 9:15 AM, [bjbq4d@gmail.com](mailto:bjbq4d@gmail.com) 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
