# Apply a role's attributes by name?

**URL:** https://discourse.chef.io/t/apply-a-roles-attributes-by-name/3067
**Category:** Chef Infra (archive)
**Created:** [August 2, 2012, 10:03pm UTC](https://discourse.chef.io/t/apply-a-roles-attributes-by-name/3067 "2012-08-02T22:03:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![John\_Alberts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/john_alberts/32/293_2.png) [@John\_Alberts](https://discourse.chef.io/u/John_Alberts)
#### Post date: [August 2, 2012, 10:03pm UTC](https://discourse.chef.io/t/apply-a-roles-attributes-by-name/3067/1 "2012-08-02T22:03:54Z")

</div>

Is there any way to apply any role’s attributes during a chef run? The  
reason I need to do this is because I am adding a role to the run\_list  
during a chef run and I’d like that role’s attributes to take effect  
during the current chef run. I know this is not idempotent and I  
shouldn’t be doing things this way, but let’s not get into that  
discussion today. 🙂

This is what I’m hoping I can do:

node[‘run\_list’] \<\< "role[roleA]"  
role.apply(“roleA”) # now the attributes in roleA will be available  
for the rest of the chef run.

Thanks in advance.  
John

---

<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: [August 2, 2012, 10:12pm UTC](https://discourse.chef.io/t/apply-a-roles-attributes-by-name/3067/2 "2012-08-02T22:12:15Z")

</div>

On Thursday, August 2, 2012 at 3:03 PM, John Alberts wrote:

> Is there any way to apply any role's attributes during a chef run? The  
> reason I need to do this is because I am adding a role to the run\_list  
> during a chef run and I'd like that role's attributes to take effect  
> during the current chef run. I know this is not idempotent and I  
> shouldn't be doing things this way, but let's not get into that  
> discussion today. 🙂
> 
> This is what I'm hoping I can do:
> 
> node['run\_list'] \<\< "role[roleA]"  
> role.apply("roleA") # now the attributes in roleA will be available  
> for the rest of the chef run.
> 
> Thanks in advance.  
> John

I think `node.expand!` after adding the role should do the trick.

--  
Dan DeLeo

---

<div class="post-metadata">

### Author: ![John\_Alberts](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/john_alberts/32/293_2.png) [@John\_Alberts](https://discourse.chef.io/u/John_Alberts)
#### Post date: [August 6, 2012, 2:58pm UTC](https://discourse.chef.io/t/apply-a-roles-attributes-by-name/3067/3 "2012-08-06T14:58:58Z")

</div>

Thanks, but unfortunately, that doesn't seem to work. I don't get any  
kind of error, but the remaining chef code doesn't seem to pick up the  
new attributes in the new role that was added. Any other ideas? 🙂

John

On Thu, Aug 2, 2012 at 5:12 PM, Daniel DeLeo [dan@kallistec.com](mailto:dan@kallistec.com) wrote:

> On Thursday, August 2, 2012 at 3:03 PM, John Alberts wrote:
> 
> > Is there any way to apply any role's attributes during a chef run? The  
> > reason I need to do this is because I am adding a role to the run\_list  
> > during a chef run and I'd like that role's attributes to take effect  
> > during the current chef run. I know this is not idempotent and I  
> > shouldn't be doing things this way, but let's not get into that  
> > discussion today. 🙂
> > 
> > This is what I'm hoping I can do:
> > 
> > node['run\_list'] \<\< "role[roleA]"  
> > role.apply("roleA") # now the attributes in roleA will be available  
> > for the rest of the chef run.
> > 
> > Thanks in advance.  
> > John
> 
> I think `node.expand!` after adding the role should do the trick.
> 
> --  
> Dan DeLeo

--  
John Alberts
