/
ohai_plugins.rb
52 lines (45 loc) · 1.42 KB
/
ohai_plugins.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
# Cookbook Name:: platformstack (originally rackops_rolebook)
# Recipe:: ohai_plugins
#
# Populate public_info attributes via an ohai plugin
#
# Copyright 2014, Rackspace, US Inc.
#
# Load the ohai recipe to populate node['ohai']
include_recipe 'ohai'
include_recipe 'git'
# Fail in a slightly more descriptive manner than the directory block below
# if the plugin directory is unset.
if node['ohai']['plugin_path'].nil?
raise 'ERROR: Ohai plugin path not set'
end
# Ensure the plugin directory exists
directory node['ohai']['plugin_path'] do
owner 'root'
group 'root'
mode '0755'
recursive true
end
git "#{Chef::Config['file_cache_path']}/ohai_plugins" do
repository Platformstack.get_rackops_platformstack(node, 'ohai_plugins', 'repo')
reference Platformstack.get_rackops_platformstack(node, 'ohai_plugins', 'ref')
action :sync
end
# this will require two converges unless we wrap it in a ruby block since the
# call to Dir[] runs before the git resource above
ruby_block 'copy plugin files to ohai from git sync in file_cache_path' do
block do
Dir["#{Chef::Config['file_cache_path']}/ohai_plugins/plugins/*"].each do |plugin|
f = Chef::Resource::RemoteFile.new("#{node['ohai']['plugin_path']}/#{File.basename(plugin)}", run_context)
f.source "file://#{plugin}"
f.owner 'root'
f.group 'root'
f.mode '0644'
f.run_action(:create)
end
end
end
ohai 'reload' do
action :reload
end