0

(chef 14.15.6 since 15 has the trapdoor license and I haven't moved to cinc)

I have the following ohai module. It's my first, so don't expect it's perfect:

# cookbooks/satellite/ohai/default.rb
Ohai.plugin(:Satellite) do

  provides 'satellite'

  def shared_method
    attribute satellite
  end

  collect_data(:default) do
    satellite Mash.new
  end
end
# cookbooks/satellite/ohai/repos.rb
Ohai.plugin(:SatelliteRepos) do

  provides "satellite/repos-id"
  depends 'satellite'

  collect_data(:linux) do
    #shared_method
    attribute satellite

    satellite['repos-id'] ||= Mash.new
    satellite['repos-name'] ||= Mash.new

    # grab repo info from a 'hammer' run
    # getting the briefer list is gonna be a mistake.
    so = shell_out('/usr/bin/hammer --csv repository list')
      .stdout
      .lines
      .map{|x| x
        .split("\n")[0]
        .split(',')}

    # "Id,Name,Product,Content Type,URL"
    header = so.shift

    so.each do |line|
      element = header
        .zip(line)              # [['ID','191'], ...]#
        .to_h                   # {'ID' => '191', ...}#

      satellite['repos-id'][element['Id']]=element
      satellite['repos-name'][element['Name']]=element['Id']
    end
  end
end

I'm loading it - it DOES load in the chef run - and I'm then reloading it after some mods so I can use it immediately.

Now here's the kicker: The cheesy hammer run is a long, long, LONG invocation, and if you know Foreman/Satellite you know it's got repos, content-views, hosts; it's a LOT of long invocations. I want to load only the sub-att if I can (but at this point I'll take anything).

How I'm reloading it with a semaphore:

:
refresh_repos = false
repos_we_need_to_add.each do |reponame|
  execute "Add repo #{reponame}" do
    command     "hammer repository create [...]"
    notifies :run, 'ruby_block[refresh repos]', :immediate
  end
end

ruby_block 'refresh repos' do
  action :nothing
  block do
    refresh_repos = true
  end
end

ohai 'reload repos' do
  action        :reload
  plugin        'satellite/repos-id'
  #plugin       'SatelliteRepos'
  only_if { refresh_repos }
end

Okay, so if you're still with me, I have a generated list to act on, and then I want to refresh the node atts.

But I can't find the right plugin name to give. I've tried :SatelliteRepos, satellite/repos when the 'provides' matched, satellite by itself, etc.

I've tried the command line: # ohai -d /var/chef/cache/cookbooks/satellite/ohai/ satellite/repos-id

This worked, but it didn't work in the ohai[reload repos] stanza. So far, nothing's worked in the reload stanza and ...

what I need, the thing I can't find, the data that eludes me, is just what to call the plugin name in the reload stanza. That's it. Assuming everything else is valid, that is, so correct me where that's wrong.

Thanks for your time and any help you can provide.

user2066657
  • 444
  • 1
  • 4
  • 23

0 Answers0