How can I override an attribute on a node with Chef?

3.4k Views Asked by At

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 ?

1

There are 1 best solutions below

7
On

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.