|
Need to Gather Additional Information About Your Infrastructure?Ohai detects data about your operating system, and can be used standalone. As it's primary purpose is to provide data to Chef, Ohai itself is included with Chef. When invoked, Ohai collects detailed, extensible information about the machine it's running on, including Chef configuration, hostname, FQDN, networking, memory, CPU, platform, and kernel data. When used standalone, Ohai will print out a JSON data blob for all the known data about your system. That data is then available to you for whatever benefit you can derive through its use.If you'd like additional information about your system infrastructure - you could write your own Custom Ohai Plugin to gather that information for you.Thanks to Community Member Christopher Sexton for this tutorial. Create a simple pluginOhai plugins use a ruby DSL Loading Your PluginCreate a "plugins" folder and put the above code in the plugins/orly.rb file. Now to fire up irb (I am assuming you are in the directory that contains the "plugins" folder, if not adjust your path): The entire script can be found in orly.rb. If you run `o.orly` and get `nil` the chances are the plugin path is probably incorrect. I battled with this for hours banging my head against the wall. Turns out I just forgot the 's' on the end of './plugins' Using a MashMost of the information we want to lookup would be nested in some way, and ohai tends to do this by storing the data in a Mash. This can be done by creating a new mash and setting the attribute to it. Working with Different PlatformsOne of the main reasons for using ohai is to gather information regardless of the operating system, luckily this is made easy by optionally loading Recipes based on the platform. With that platform specific calls abstracted away you can keep your code DRY. The builtin plugins that come with ohai use the following trick to load platform specific code: It works by creating a base cross-platform plugin that loads the platform specific plugin from a subdirectory. In plugins/lolcode.rb: Checkout ohai's os.rb for the list of platform names. All of these examples can be found in the ohai-plugin-howto github repo, you should be able to clone that and run the ruby scripts in the repo's root directory. If you figure out any other handy tricks please fork the project and add them. Extending an existing pluginOhai makes it very easy to extend a current plugin with new information. Simply require the plugin you want to extend and extend away. In this example we want to add LOLCODE to languages. Chef Community PluginsReview (or contribute to) a collection of Community Plugins Found In The Wild. You may find a plugin created by someone in the community that fills a need. And if you end up creating one that you believe may have appeal beyond your infrastructure, please contribute it to the community for others as well. Loading and Distributing Custom Ohai PluginsLoading Custom Ohai Plugins provides detail on how to load a custom plugin to chef-client. Distributing Ohai Plugins details how to distribute custom plugins to your Nodes.
|
|
|


