I have a code snippet at the beginning of my recipe that checks to make sure that certain attributes are set, it looks like this:
if !node['consul']['dns'].has_key?("nameserver1")
raise "Please set a value for nameserver1"
end
but when I run chef-client, it returns:
undefined method `has_key?' for nil:NilClass
...
1>> if !node['consul']['dns'].has_key?("nameserver1")
2: raise "Please set a value for nameserver1"
3: end
Which looks to me to mean that either the consul
attribute does not exist, or the dns
attribute does not exist inside of it.
However, my holding.json file contains this:
"consul": {
"dns": {
"nameserver1": "IPADDR1",
"nameserver2": "IPADDR1",
"nameserver3": "IPADDR1",
"nameserver4": "IPADDR1"
}
},
and I’ve confirmed the node is in that environment by checking inside of knife node edit:
"chef_environment": "holding"
Why might it not be picking up those attributes?? In holding.json, those attributes are located in the default attributes section.