Chef Node Attributes. Which ones are avaialble?
Solution 1
Are all node[...] defined automatically?
No. some of them are set by Ohai at the start of a chef run. Some of them are set by (default) attributes of cookbooks and some of them are overwritten at various places in the system (e.g. roles, other recipes, ...)
Where can I find a list of all available node attributes (cpu...)?
That depends on the system you are running at, which ohai plugins you have installed and which cookbooks you have in your runlist. To get the full list of basic Ohai attributes, you can simply execute ohai
on your shell which will output all automatic attributes. For the others, you have to look at your cookbooks.
For documentation reference have a look at the Chef documentation. I linked a good starting point, but really understanding attributes is a bit complex as it is a rather flexible (and thus complex) system. You should browse a bit of the documentation.
Solution 2
Ah! So it's the Ohai recipe/plugin that sets attributes. Specifically the linux/cpu plugin.
Solution 3
Might help for others in future :
List of all automatic attributes for a node : ( Depends on ohai plugin version)
The list of automatic attributes that are collected by Ohai at the start of each chef-client run vary from organization to organization, and will often vary between the various server types being configured and the platforms on which those servers are run. All attributes collected by Ohai are unmodifiable by the chef-client. To see which automatic attributes are collected by Ohai for a particular node, run the following command:
find /opt/chefdk/embedded/lib/ruby/gems/*/gems/ohai-*/lib -name "*.rb" -print | xargs grep -R "provides" -h |sed 's/^\s*//g'|sed "s/\\\"/\'/g"|sort|uniq|grep "^provides"
Referenced from : https://docs.chef.io/ohai.html
iDev247
I'm a web developer working mostly with PHP (CakePHP, ExpressionEngine, Magento) as backend and JavaScript (jQuery), XHTML Strict and HTML5 as frontend.
Updated on June 11, 2022Comments
-
iDev247 almost 2 years
I just started using Chef and I've noticed in some recipes there's stuff like
node['cpu']['total']
.I searched in questions and online for stuff like "chef node attributes" but I can't find a list of available node attributes.
What I'm looking for is:
- Are all
node[...]
defined automatically? - Where can I find a list of all available node attributes (cpu...)?
- Are all
-
iDev247 about 11 yearsAnyone know where I can get a list of the available values? You can post as an answer to take the cred.
-
iDev247 about 11 yearsWow! Amazing response. Extremely useful. I didn't know ohai was executable. It might come in handy things other than Chef.... I have been struggling with Chef. I'm not used to the way it's documented. Thanks!