1

An attribute for a chef node is not being updated when I change the role, the old value is persisting.

The node['nagios']['custom_variables']['styleurl'] attribute is not updating to the new value of /urlprefix, and is stuck on an old value urlprefix. I changed the role definition more than a week ago.

Another node with chef-client (which is the nagios server which looks at this attributes):

# chef-shell -z
chef > nodes.show("server2.example.com")['nagios']['custom_variables']['styleurl']
 => "urlprefix"

The node and role definitions (below) don't include this value, and only include /urlprefix.

debug_value tells me this comes from an override.

chef > nodes.show("server2.example.com").debug_value("nagios", "custom_variables", "styleurl")
=> [["set_unless_enabled?", false], ["default", :not_present], ["env_default", :not_present], ["role_default", :not_present], ["force_default", :not_present], ["normal", :not_present], ["override", "osm"], ["role_override", :not_present], ["env_override", :not_present], ["force_override", :not_present], ["automatic", :not_present]] 

knife node show -l shows me that there is an override for that variable. (see below for output).

I use these attributes to configure my nagios checks. Nagios is configured with chef, so obviously my nagios checks are failing.

How come I can't change the attribute in the role? Why doesn't the role override_attribute not, well overrride the attribue? How can I change this attribute?

Node configuration

Simple node, everything is done in the role.

$ knife node show -Fjson server2.example.com
{
  "name": "server2.example.com",
  "chef_environment": "_default",
  "run_list": [
    "role[server2]"
  ],
  "normal": {
    "tags": []
  }
}

Role

Only server2.example.com has the server2 role. Everything is done in the role. This is the only place the styleurl is set.

$ knife role show -Fjson server2
{
  "name": "server2",
  "description": "",
  "json_class": "Chef::Role",
  "default_attributes": {
  },
  "override_attributes": {
    "nagios": {
      "custom_variables": {
        "styleurl": "/urlprefix"
      }
    }
  },
  "chef_type": "role",
  "run_list": [
    "role[ubuntu-precise-basic]",
    "recipe[firewall::http]",
    "recipe[firewall::https]"
  ],
  "env_run_lists": {
  }
}

Cookbook attributes

The custom_variables::styleurl is not defined anywhere in the cookbook:

$ grep -R "custom_variables" cookbooks/
cookbooks/nagios/templates/default/hosts.cfg.erb:  <% if node['nagios'] && node['nagios']['custom_variables'] %>
cookbooks/nagios/templates/default/hosts.cfg.erb:  <% node['nagios']['custom_variables'].each do |key, value| -%>
cookbooks/nagios/templates/default/hosts.cfg.erb:  <% if n['nagios'] && n['nagios']['custom_variables'] %>
cookbooks/nagios/templates/default/hosts.cfg.erb:  <% n['nagios']['custom_variables'].each do |key, value| -%>
cookbooks/nagios/templates/default/hosts.cfg.erb:  <% if n['nagios'] && n['nagios']['custom_variables'] %>
cookbooks/nagios/templates/default/hosts.cfg.erb:  <% n['nagios']['custom_variables'].each do |key, value| -%>
$

knife node show

(partially redacted/edited)

$ knife node show -Fjson  -l server2.example.com
{
  "name": "server2.example.com",
  "chef_environment": "_default",
  "run_list": [
    "role[server2]"
  ],
  "normal": {
    "tags": [

    ]
  },
  "override": {
    "nagios": {
      "custom_variables": {
        "styleurl": "osm"
      }
    }
  },
    ...
    "recipes": [
      "accounts",
      "packages::precise",
      "firewall::ssh",
      "firewall::munin",
      "firewall::nrpe",
      "munin::client",
      "munin-checks",
      "nrpe",
      "nagios-checks",
      "fail2ban",
      "openssh",
      "mycompany::apache_logrotate",
      "firewall::http",
      "firewall::https"
    ],
    "roles": [
      "server2",
      "ubuntu-precise-basic",
      "mycompany-accounts"
    ]
  }
}

Chef v11.8

0

After posting this question, I tried to run chef-client on the server2.example.com node directly. And now knife & the other node can see the correct node attributes, and the problem is fixed.

So "Run chef-client on the affeected node" fixes this problem.

| improve this answer | |
0

To further explain a bit: the node object contains two kinds of data. The "desired state" like the run list and chef environment are generally updated by a human so they would always look up to date. The "current state" (mostly in the form of node attributes) is only saved back up the Chef Server at the end of a successful converge to document the state of the machine at that moment.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.