1

We have a Chef environment setup. Our deployments work fine, with node attributes properly overridden by roles and environments.

In order to test an upcoming change, we want to change a setting on 1 particular node in our deployment. We don't want to write a different recipe, role or environment for that test as there is really only 1 setting different.

I tried via Chef Manage's web UI and set the particular node's attribute as follows:

{
    "tags": null,
    "our_app":{
        "url": "http://test-server"
    }
}

In our cookbook the attributes/default.rb is set as follows:

default[:our_app][:url] = ''

In our environment file, we override the setting as follows:

override_attributes({
    "our_app" => {
        "url" => "http://default-server",
    }
})

We use the following .erb template inside our recipe:

{
    "serverUrl": "<%= node[:our_app][:url]%>"
}

However, when we run chef-client on that node, it still ends up with http://default-server in the output.

I understand the attribute precedence as explained in the docs . But I am not sure how to achieve what I want.

Am I supposed to not use override_attributes() in my environment file?

Is there a way to have a node-specific override attribute ?

Eric Liprandi
  • 5,324
  • 2
  • 49
  • 68

1 Answers1

2

No, there is no way of having a node-specific override. The node specific data is always (and the only thing at) the normal level. You should, in general, not be using override levels at all, and certainly not for something calling itself a default value.

Also we really recommend not using roles/envs anymore. You should switch to the Policyfile system as soon as you get a chance.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Thanks. Unfortunately, I have little control over what IT currently has setup and our current standard is roles/env. So I am trying to work with that. I tried changing my environment file to `default_attributes()` instead and setting the node's `override` attributes. But that does not seem to work either. The override is showing in the `knife edit -a` command and in the `knife show -l` but it does not seem to be used. – Eric Liprandi Jul 30 '18 at 23:59
  • 1
    You can't set a node's override attributes, it has no such thing. You see echo'd data in the node object that is saved back off the node at the end of a successful converge, to be used for search() and for reporting stuff, but it's not an input. Only roles, envs, and cookbooks can set at the override level(s). – coderanger Jul 31 '18 at 01:07
  • so there is no way for me to force a node attribute for 1 particular node without doing it in the env/roles/recipes? – Eric Liprandi Jul 31 '18 at 16:26
  • 1
    There is, but only if you've been careful to set the majority of your attrs at a `default` level, which you should be doing. `override` is only for emergencies, like `!important` in CSS. – coderanger Jul 31 '18 at 20:58
  • can you point me to the documentation or article about how to do this? I actually went and rewrote most of my envs/roles as `default` instead of `override` (I inherited the code...). So, I would be ready to try your solution if you have one. Thanks in advance. – Eric Liprandi Aug 01 '18 at 21:45
  • 1
    Just put it in the `normal` level in the node object as per usual. That is "above" `default` to it would take priority. – coderanger Aug 01 '18 at 22:06
  • doh! thanks @coderanger. I feel silly about that last question now. I realized that after I tried so many different setup it was all screwed up. I just went through the WebUI (or `knife`), set the attribute and it worked like a charm... – Eric Liprandi Aug 02 '18 at 17:17