# Roles with same runlist, overriding same attributes - to be used on same node

**URL:** https://discourse.chef.io/t/roles-with-same-runlist-overriding-same-attributes-to-be-used-on-same-node/4943
**Category:** Chef Infra (archive)
**Created:** [January 24, 2014, 1:25pm UTC](https://discourse.chef.io/t/roles-with-same-runlist-overriding-same-attributes-to-be-used-on-same-node/4943 "2014-01-24T13:25:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Sharmanitishdutt](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/sharmanitishdutt/32/392_2.png) [@Sharmanitishdutt](https://discourse.chef.io/u/Sharmanitishdutt)
#### Post date: [January 24, 2014, 1:25pm UTC](https://discourse.chef.io/t/roles-with-same-runlist-overriding-same-attributes-to-be-used-on-same-node/4943/1 "2014-01-24T13:25:02Z")

</div>

Hello chefs,  
We are testing our chef setup with our infrastructure and came across an  
interesting situation. We have separate roles for each application, to setup  
application specific files and environment. These roles have exact same runlist  
and override exact same set of attributes (with different values, of course).  
For testing, we assigned all the roles to one node.  
Now running chef-client on the server resulted in only 1 execution of the  
runlist. So we thought that it might be because runlist being resolved to same  
set of recipes for all the roles. We then created different recipe for each  
application and added it to the corresponding role. Now the roles consist of  
different recipes but still override same set of attributes. Chef-client now  
runs all the recipes but using the attribute values overridden by the _last  
role assigned_ to the node i.e. all the roles are executed using same attribute  
values.  
I have tried many different combinations but none of them lead to expected  
behaviour i.e. ability to run different roles, with same runlist and overriding  
same attributes, on the same node.  
Any suggestions are highly appreciated.

Cheers

---

<div class="post-metadata">

### Author: ![Cassiano\_Leal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/cassiano_leal/32/86_2.png) [@Cassiano\_Leal](https://discourse.chef.io/u/Cassiano_Leal)
#### Post date: [January 24, 2014, 1:52pm UTC](https://discourse.chef.io/t/roles-with-same-runlist-overriding-same-attributes-to-be-used-on-same-node/4943/2 "2014-01-24T13:52:26Z")

</div>

Whatdid you é spect to achieve?

On Friday, January 24, 2014 at 13:25, [sharmanitishdutt@gmail.com](mailto:sharmanitishdutt@gmail.com) wrote:

> Hello chefs,  
> We are testing our chef setup with our infrastructure and came across an  
> interesting situation. We have separate roles for each application, to setup  
> application specific files and environment. These roles have exact same runlist  
> and override exact same set of attributes (with different values, of course).  
> For testing, we assigned all the roles to one node.  
> Now running chef-client on the server resulted in only 1 execution of the  
> runlist. So we thought that it might be because runlist being resolved to same  
> set of recipes for all the roles. We then created different recipe for each  
> application and added it to the corresponding role. Now the roles consist of  
> different recipes but still override same set of attributes. Chef-client now  
> runs all the recipes but using the attribute values overridden by the _last  
> role assigned_ to the node i.e. all the roles are executed using same attribute  
> values.  
> I have tried many different combinations but none of them lead to expected  
> behaviour i.e. ability to run different roles, with same runlist and overriding  
> same attributes, on the same node.  
> Any suggestions are highly appreciated.
> 
> Cheers

---

<div class="post-metadata">

### Author: ![anon74631265](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@anon74631265](https://discourse.chef.io/u/anon74631265)
#### Post date: [January 24, 2014, 2:24pm UTC](https://discourse.chef.io/t/roles-with-same-runlist-overriding-same-attributes-to-be-used-on-same-node/4943/3 "2014-01-24T14:24:48Z")

</div>

Uh... yeah. Thinking about it as code

-- BEGIN CODE --  
@attribute = ""  
def converge\_node() {  
puts "We're doing stuff with #{@attribute}"

# go and do converge stuff

}

@attribute = "foo"  
@attribute = "bar"  
converge\_node()

-- END CODE --

I would not expect to see a line saying "We're doing stuff with foo"  
because I'm overriding the exact same attributes with different values that  
my converge\_role method is using. There should not be an expectation  
chef-client (or my simple converge\_node method) should know the history of  
the attribute and whatever values it might have had prior in the program  
run.

If you want your roles to work with multiple different attributes, you  
might want to look into making the attributes "arrayable", then check if  
they have a single value or multiple values and react appropriately. This  
requires work and testing, though, and may be a somewhat complicated  
process to implement.

On Fri, Jan 24, 2014 at 8:25 AM, [sharmanitishdutt@gmail.com](mailto:sharmanitishdutt@gmail.com) wrote:

> Hello chefs,  
> We are testing our chef setup with our infrastructure and came across an  
> interesting situation. We have separate roles for each application, to  
> setup  
> application specific files and environment. These roles have exact same  
> runlist  
> and override exact same set of attributes (with different values, of  
> course).  
> For testing, we assigned all the roles to one node.  
> Now running chef-client on the server resulted in only 1 execution of the  
> runlist. So we thought that it might be because runlist being resolved to  
> same  
> set of recipes for all the roles. We then created different recipe for each  
> application and added it to the corresponding role. Now the roles consist  
> of  
> different recipes but still override same set of attributes. Chef-client  
> now  
> runs all the recipes but using the attribute values overridden by the _last  
> role assigned_ to the node i.e. all the roles are executed using same  
> attribute  
> values.  
> I have tried many different combinations but none of them lead to expected  
> behaviour i.e. ability to run different roles, with same runlist and  
> overriding  
> same attributes, on the same node.  
> Any suggestions are highly appreciated.
> 
> Cheers
