Skip to content

Files

Latest commit

3cf4cf7 · Feb 26, 2020

History

History
69 lines (50 loc) · 1.33 KB

ctl_ohai.md

File metadata and controls

69 lines (50 loc) · 1.33 KB

+++ title = "ohai (executable)" draft = false

aliases = ["/ctl_ohai.html"]

[menu] [menu.docs] title = "ohai (executable)" identifier = "chef_infra/features/ohai/ctl_ohai.md ohai (executable)" parent = "chef_infra/features/ohai" weight = 20 +++

[edit on GitHub]

{{% ctl_ohai_summary %}}

Options

{{% ctl_ohai_options %}}

Examples

The following examples show how to use the Ohai command-line tool:

Run a plugin independently of a Chef Infra Client run

An Ohai plugin can be run independently of a Chef Infra Client run. First, ensure that the plugin is located in the /plugins directory and then use the -f option when running Ohai from the command line. For example, a plugin named sl_installed may look like the following:

Ohai.plugin(:Sl) do
  provides "sl"

  collect_data(:default) do
    sl Mash.new

    if ::File.exist?("/usr/games/sl")
      sl[:installed] = true
    else
      sl[:installed] = false
    end

    # sl[:installed] = ::File.exist?("/usr/games/sl")

  end
end

To run that plugin from the command line, use the following command:

ohai --directory /path/to/directory sl

The command will return something similar to:

{
  "sl": {
    "installed": true
  }
}