# Node or Role Attribute reference via Chef::Resource::Script::Bash

**URL:** <https://discourse.chef.io/t/node-or-role-attribute-reference-via-chef-resource-script-bash/5361>\
**Category:** Chef Infra (archive)\
**Created:** [May 30, 2014, 7:24pm UTC](https://discourse.chef.io/t/node-or-role-attribute-reference-via-chef-resource-script-bash/5361 "2014-05-30T19:24:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Chait](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@David\_Chait](https://discourse.chef.io/u/David_Chait)\
**Post date:** [May 30, 2014, 7:24pm UTC](https://discourse.chef.io/t/node-or-role-attribute-reference-via-chef-resource-script-bash/5361/1 "2014-05-30T19:24:27Z")

</div>

All,  
I apologize if this is a rather basic question, but I cannot seem  
to find a clear answer. I am trying to pull a node or role based  
attribute into only\_if or not\_if logic within a Bash block, though so  
far without a lot of luck. A\> Is it possible? B\> If so, how?

Thanks,  
David

---

<div class="post-metadata">

**Author:** ![jdunn](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/jdunn/32/1800_2.png) [@jdunn](https://discourse.chef.io/u/jdunn)\
**Post date:** [May 30, 2014, 10:23pm UTC](https://discourse.chef.io/t/node-or-role-attribute-reference-via-chef-resource-script-bash/5361/2 "2014-05-30T22:23:08Z")

</div>

Sure, does something like this not work?

$ chef-apply -s  
execute 'echo hi' do  
only\_if { node['hostname'] == 'foobar' }  
end  
Recipe: (chef-apply cookbook)::(chef-apply recipe)

- execute[echo hi] action run (skipped due to only\_if)

- Julian

On Fri, May 30, 2014 at 3:24 PM, David Chait [chaitdavid@gmail.com](mailto:chaitdavid@gmail.com) wrote:

> All,  
> I apologize if this is a rather basic question, but I cannot seem  
> to find a clear answer. I am trying to pull a node or role based  
> attribute into only\_if or not\_if logic within a Bash block, though so  
> far without a lot of luck. A\> Is it possible? B\> If so, how?
> 
> Thanks,  
> David

--  
[Julian C. Dunn [jdunn@aquezada.com](mailto:jdunn@aquezada.com) \* Sorry, I'm ]  
[WWW: [Julian Dunn's Blog - Commentary on media, technology, and everything in between.](http://www.aquezada.com/staff/julian) \* only Web 1.0 ]  
[gopher://sdf.org/1/users/keymaker/ \* compliant!]  
[PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9]

---

<div class="post-metadata">

**Author:** ![David\_Chait](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@David\_Chait](https://discourse.chef.io/u/David_Chait)\
**Post date:** [May 30, 2014, 10:36pm UTC](https://discourse.chef.io/t/node-or-role-attribute-reference-via-chef-resource-script-bash/5361/3 "2014-05-30T22:36:55Z")

</div>

Thanks Julian,  
I was over thinking the problem and ended up with something far  
less elegant. I appreciate the help.

Cheers,  
David

On Fri, May 30, 2014 at 3:23 PM, Julian C. Dunn [jdunn@aquezada.com](mailto:jdunn@aquezada.com) wrote:

> Sure, does something like this not work?
> 
> $ chef-apply -s  
> execute 'echo hi' do  
> only\_if { node['hostname'] == 'foobar' }  
> end  
> Recipe: (chef-apply cookbook)::(chef-apply recipe)
> 
> - execute[echo hi] action run (skipped due to only\_if)
> 
> - Julian
> 
> On Fri, May 30, 2014 at 3:24 PM, David Chait [chaitdavid@gmail.com](mailto:chaitdavid@gmail.com) wrote:
> 
> > All,  
> > I apologize if this is a rather basic question, but I cannot seem  
> > to find a clear answer. I am trying to pull a node or role based  
> > attribute into only\_if or not\_if logic within a Bash block, though so  
> > far without a lot of luck. A\> Is it possible? B\> If so, how?
> > 
> > Thanks,  
> > David
> 
> --  
> [Julian C. Dunn [jdunn@aquezada.com](mailto:jdunn@aquezada.com) \* Sorry, I'm ]  
> [WWW: [Julian Dunn's Blog - Commentary on media, technology, and everything in between.](http://www.aquezada.com/staff/julian) \* only Web 1.0 ]  
> [gopher://sdf.org/1/users/keymaker/ \* compliant!]  
> [PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9]
