How to override a node default variable in environment

I have setup a default variable in cookbook default attribute like below

node.default['splunk']['workflow']['do_conf'] = 1

I use this variable as the switch on/off of the template creation in the recipe.

template "/opt/splunk/etc/system/local/server.conf" do
    ....
    notifies :restart, 'service[splunk]', :delayed
    only_if { node['splunk']['workflow']['do_conf'] == 1 }
end

I would like to override it in environment env1. This is the environment called env1(son format)

{
  "name": "env1",
  "description": "test env",
  "cookbook_versions": {
  },
  "json_class": "Chef::Environment",
  "chef_type": "environment",
  "default_attributes": {
    "node": {
      "splunk": {
        "workflow": {
           "do_conf": 0
        }
      }
    }
  },
  "override_attributes": {
  }
}

But it seems not working, the template is still created and notify the service to restart.

Is anything wrong in my attribute/recipe/environment?

Hi. There are a few things I would like to mention here:

  1. Try not to set attributes in recipes, but rather set them in the attribute files. If you read that in the Berkshelf workflow docs then don’t think the stuff in there is invalid or bad. It is still very much valid but a lot has changed since then and using the attribute files rather is one of them in my eyes.
  2. In your environment you have default_attributes -> node -> splunk which should be default_attributes -> splunk.
  3. You can test all of then in Kitchen if you don’t already do. Check the kitchen docs and/or kitchen diagnose on how to set the environment stuff.