# Creating attributes that are tied to Environment and Roles

**URL:** <https://discourse.chef.io/t/creating-attributes-that-are-tied-to-environment-and-roles/2281>\
**Category:** Chef Infra (archive)\
**Created:** [December 22, 2011, 2:04am UTC](https://discourse.chef.io/t/creating-attributes-that-are-tied-to-environment-and-roles/2281 "2011-12-22T02:04:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zuhaib\_Siddique](https://avatars.discourse-cdn.com/v4/letter/z/d9b06d/32.png) [@Zuhaib\_Siddique](https://discourse.chef.io/u/Zuhaib_Siddique)\
**Post date:** [December 22, 2011, 2:04am UTC](https://discourse.chef.io/t/creating-attributes-that-are-tied-to-environment-and-roles/2281/1 "2011-12-22T02:04:34Z")

</div>

Hey All,

I am trying to figure out a solution to a problem I got and I think its not unique but I can seem to find a clear answer on this in the wiki. So I have a cookbook that will add your current server to a ELB pool but for it to work you must pass it an attributes with the ELB name which we set as a role attribute. This would be fine but the problem is I need the name to change based on the chef environment we are using to deploy. Now I can set a environment attribute but I have different ELB’s and they need to be added based on their roles. How can I create something that is tied to both the environment and role.

Thanks  
Zuhaib

---

<div class="post-metadata">

**Author:** ![Sean\_OMeara](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/sean_omeara/32/435_2.png) [@Sean\_OMeara](https://discourse.chef.io/u/Sean_OMeara)\
**Post date:** [December 22, 2011, 5:38am UTC](https://discourse.chef.io/t/creating-attributes-that-are-tied-to-environment-and-roles/2281/2 "2011-12-22T05:38:02Z")

</div>

You can set attributes directly in environments as well as roles  
starting in 0.10.0.

[http://wiki.opscode.com/display/chef/Attributes#Attributes-EnvironmentAttributes](http://wiki.opscode.com/display/chef/Attributes#Attributes-EnvironmentAttributes)

Just use the normal override\_attribute syntax and you should be good to go.

-s

On Wed, Dec 21, 2011 at 9:04 PM, Zuhaib Siddique  
[zuhaib.siddique@leapfile.com](mailto:zuhaib.siddique@leapfile.com) wrote:

> Hey All,
> 
> I am trying to figure out a solution to a problem I got and I think its not unique but I can seem to find a clear answer on this in the wiki. So I have a cookbook that will add your current server to a ELB pool but for it to work you must pass it an attributes with the ELB name which we set as a role attribute. This would be fine but the problem is I need the name to change based on the chef environment we are using to deploy. Now I can set a environment attribute but I have different ELB's and they need to be added based on their roles. How can I create something that is tied to both the environment and role.
> 
> Thanks  
> Zuhaib

---

<div class="post-metadata">

**Author:** ![Zuhaib\_Siddique](https://avatars.discourse-cdn.com/v4/letter/z/d9b06d/32.png) [@Zuhaib\_Siddique](https://discourse.chef.io/u/Zuhaib_Siddique)\
**Post date:** [December 22, 2011, 6:35am UTC](https://discourse.chef.io/t/creating-attributes-that-are-tied-to-environment-and-roles/2281/3 "2011-12-22T06:35:34Z")

</div>

S,

Yeah I was looking at that but it has a few problems, its an environment settings so it applies to all attributes. So example I have a role named Server1 that needs to be added to ELB1 and then I have Server2 that needs to be added to ELB2. I cant do that if the attribute for the env is AWS:ELB:NAME: ELB1.

Zuhaib  
On Dec 21, 2011, at 9:38 PM, Sean OMeara wrote:

> You can set attributes directly in environments as well as roles  
> starting in 0.10.0.
> 
> [http://wiki.opscode.com/display/chef/Attributes#Attributes-EnvironmentAttributes](http://wiki.opscode.com/display/chef/Attributes#Attributes-EnvironmentAttributes)
> 
> Just use the normal override\_attribute syntax and you should be good to go.
> 
> -s
> 
> On Wed, Dec 21, 2011 at 9:04 PM, Zuhaib Siddique  
> [zuhaib.siddique@leapfile.com](mailto:zuhaib.siddique@leapfile.com) wrote:
> 
> > Hey All,
> > 
> > I am trying to figure out a solution to a problem I got and I think its not unique but I can seem to find a clear answer on this in the wiki. So I have a cookbook that will add your current server to a ELB pool but for it to work you must pass it an attributes with the ELB name which we set as a role attribute. This would be fine but the problem is I need the name to change based on the chef environment we are using to deploy. Now I can set a environment attribute but I have different ELB's and they need to be added based on their roles. How can I create something that is tied to both the environment and role.
> > 
> > Thanks  
> > Zuhaib
