# Check for changed attribute values

**URL:** <https://discourse.chef.io/t/check-for-changed-attribute-values/5136>\
**Category:** Chef Infra (archive)\
**Created:** [March 18, 2014, 4:06pm UTC](https://discourse.chef.io/t/check-for-changed-attribute-values/5136 "2014-03-18T16:06:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stewart\_Curtis](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/stewart_curtis/32/237_2.png) [@Stewart\_Curtis](https://discourse.chef.io/u/Stewart_Curtis)\
**Post date:** [March 18, 2014, 4:06pm UTC](https://discourse.chef.io/t/check-for-changed-attribute-values/5136/1 "2014-03-18T16:06:57Z")

</div>

Is there anyway to check if a node attribute has changed since the last chef-client run?

My particular case is to run a rake task ONLY IF the specified git branch attribute has changed since the last chef-client run.

Thanks,  
Curtis

---

<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:** [March 18, 2014, 4:44pm UTC](https://discourse.chef.io/t/check-for-changed-attribute-values/5136/2 "2014-03-18T16:44:29Z")

</div>

On Tuesday, March 18, 2014 at 9:06 AM, Stewart, Curtis wrote:

> Is there anyway to check if a node attribute has changed since the last chef-client run?
> 
> My particular case is to run a rake task ONLY IF the specified git branch attribute has changed since the last chef-client run.
> 
> Thanks,  
> Curtis

The old state isn’t kept around. Would it be possible to look at the state of the system to figure this out, e.g., add something like

```
only_if “git branch SOMETHING SOMETHING”

```

to your execute resource?

--  
Daniel DeLeo

---

<div class="post-metadata">

**Author:** ![Joe\_Nuspl](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/joe_nuspl/32/3243_2.png) [@Joe\_Nuspl](https://discourse.chef.io/u/Joe_Nuspl)\
**Post date:** [March 18, 2014, 5:09pm UTC](https://discourse.chef.io/t/check-for-changed-attribute-values/5136/3 "2014-03-18T17:09:49Z")

</div>

Within a chef client run? You could do something like…

```
last = Chef::Node.load(node.name)
if last.default[‘some-attribute’] != node.default[‘some-attribute’]
	# do something
end

```

This only works is you call Chef::Node.load before any recipe does a "node.save”. Substitute “override” for “default” if you’re looking at overrides.

If external to a client run and you are loading node attributes via role/cookbook/data\_bag backed by git, you could use "knife node show” and compare that to what the new code would load and then execute rake.

Hope this helps.

```
Joe

```

On Mar 18, 2014, at 9:06 AM, Stewart, Curtis [cstewart@momentumsi.com](mailto:cstewart@momentumsi.com) wrote:

> Is there anyway to check if a node attribute has changed since the last chef-client run?
> 
> My particular case is to run a rake task ONLY IF the specified git branch attribute has changed since the last chef-client run.
> 
> Thanks,  
> Curtis

---

<div class="post-metadata">

**Author:** ![Jeremy\_Mauro](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@Jeremy\_Mauro](https://discourse.chef.io/u/Jeremy_Mauro)\
**Post date:** [March 19, 2014, 2:07pm UTC](https://discourse.chef.io/t/check-for-changed-attribute-values/5136/4 "2014-03-19T14:07:08Z")

</div>

One way to do it would be keep some kind of changelog of the value into a file for example then ‘subscribe an action’:  
file ‘/var/cache/chef/gitbranch’ do  
content node[‘someattributs’]  
notifies :run, 'whatever resource I want’  
end

From: Joe Nuspl [[mailto:nuspl@nvwls.com](mailto:nuspl@nvwls.com)]  
Sent: mardi 18 mars 2014 18:10  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Re: Check for changed attribute values

Within a chef client run? You could do something like…

```
        last = Chef::Node.load(node.name)
        if last.default['some-attribute'] != node.default['some-attribute']
                    # do something
        end

```

This only works is you call Chef::Node.load before any recipe does a “node.save”. Substitute “override” for “default” if you’re looking at overrides.

If external to a client run and you are loading node attributes via role/cookbook/data\_bag backed by git, you could use “knife node show” and compare that to what the new code would load and then execute rake.

Hope this helps.

```
        Joe

```

On Mar 18, 2014, at 9:06 AM, Stewart, Curtis \<[cstewart@momentumsi.com](mailto:cstewart@momentumsi.com)[mailto:cstewart@momentumsi.com](mailto:cstewart@momentumsi.com)\> wrote:

Is there anyway to check if a node attribute has changed since the last chef-client run?

My particular case is to run a rake task ONLY IF the specified git branch attribute has changed since the last chef-client run.

Thanks,  
Curtis

---

<div class="post-metadata">

**Author:** ![Stewart\_Curtis](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/stewart_curtis/32/237_2.png) [@Stewart\_Curtis](https://discourse.chef.io/u/Stewart_Curtis)\
**Post date:** [March 19, 2014, 2:15pm UTC](https://discourse.chef.io/t/check-for-changed-attribute-values/5136/5 "2014-03-19T14:15:24Z")

</div>

I really like the file idea. It allows use of notifications. We’ll try to look into that.

Thanks for the feedback!

Curtis

On Mar 19, 2014, at 9:07 AM, Jeremy Mauro \<[j.mauro@criteo.com](mailto:j.mauro@criteo.com)[mailto:j.mauro@criteo.com](mailto:j.mauro@criteo.com)\> wrote:

One way to do it would be keep some kind of changelog of the value into a file for example then ‘subscribe an action’:  
file ‘/var/cache/chef/gitbranch’ do  
content node[‘someattributs’]  
notifies :run, ‘whatever resource I want’  
end

From: Joe Nuspl [[mailto:nuspl@nvwls.com](mailto:nuspl@nvwls.com)]  
Sent: mardi 18 mars 2014 18:10  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)[mailto:chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Re: Check for changed attribute values

Within a chef client run? You could do something like…

```
        last = Chef::Node.load(node.name)
        if last.default[‘some-attribute’] != node.default[‘some-attribute’]
                    # do something
        end

```

This only works is you call Chef::Node.load before any recipe does a "node.save”. Substitute “override” for “default” if you’re looking at overrides.

If external to a client run and you are loading node attributes via role/cookbook/data\_bag backed by git, you could use "knife node show” and compare that to what the new code would load and then execute rake.

Hope this helps.

```
        Joe

```

On Mar 18, 2014, at 9:06 AM, Stewart, Curtis \<[cstewart@momentumsi.com](mailto:cstewart@momentumsi.com)[mailto:cstewart@momentumsi.com](mailto:cstewart@momentumsi.com)\> wrote:

Is there anyway to check if a node attribute has changed since the last chef-client run?

My particular case is to run a rake task ONLY IF the specified git branch attribute has changed since the last chef-client run.

Thanks,  
Curtis
