[chef] Re: Attributes merged between roles and environments?


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: Attributes merged between roles and environments?
  • Date: Tue, 12 Aug 2014 15:08:49 -0700

On Tuesday, August 12, 2014 at 3:03 PM, Douglas Garstang wrote:
> This seems to be the case, but I thought I'd check, just in case I'm making 
> incorrect assumptions...
>  
> Do multi level attributes get 'merged' between environments and roles? Ie, 
> would this environment attribute:
>  
> {
> "name": "qa",
> "default_attributes": {
> "mongodb": {
> "cluster_name": "test1"
> }
> }
>  
> and this role attribute:
>  
> {
> "name": "role-mongo-shard1",
> "default_attributes": {
> "mongodb": {
> "shard_name": "shard1",
> "config": {
> "replSet": "replset1"
> }
> }
> }
> }
>  
> be merged into this json?
>  
> mongodb": {
> "cluster_name": "test1",
> "shard_name": "shard1",
> "config": {
> "replSet": "replset1"
> }
> }
>  
> Or, does one wipe the other?
>  
> Thanks,
> Doug.  

They’re “deep merged,” which does what you expect as long as everything is a 
hash (JSON “object” type). With Arrays, it’s tricky because we try to make a 
compromise that supports two competing use cases (sometimes you want a set 
union, sometimes you want replacement). The best way to go is just to steer 
clear of Arrays entirely and it should work as you expect.

--  
Daniel DeLeo






Archive powered by MHonArc 2.6.16.

§