]> git.openstreetmap.org Git - chef.git/blob - cookbooks/ohai/resources/plugin.rb
foundation: use default mediawiki version
[chef.git] / cookbooks / ohai / resources / plugin.rb
1 #
2 # Cookbook:: ohai
3 # Resource:: ohai_plugin
4 #
5 # Copyright:: 2015, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # https://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 unified_mode true
21
22 default_action :create
23
24 property :plugin, :kind_of => String, :name_property => true
25 property :template, :kind_of => String, :required => [:create]
26
27 action :create do
28   ohai new_resource.plugin do
29     action :nothing
30   end
31
32   directory "/etc/cinc/ohai/plugins" do
33     owner "root"
34     group "root"
35     mode "755"
36     recursive true
37   end
38
39   # cinc ohai v18.2.8 still uses plugin_path => "/etc/chef/ohai/plugins"
40   # so we need to ensure it exists and is linked to the correct cinc directory
41   directory "/etc/chef/ohai" do
42     owner "root"
43     group "root"
44     mode "755"
45     recursive true
46   end
47
48   link "/etc/chef/ohai/plugins" do
49     to "/etc/cinc/ohai/plugins"
50     owner "root"
51     group "root"
52     not_if { ::File.exist?("/etc/chef/ohai/plugins") }
53   end
54
55   declare_resource :template, plugin_path do
56     source new_resource.template
57     owner "root"
58     group "root"
59     mode "644"
60     notifies :reload, "ohai[#{new_resource.plugin}]"
61   end
62 end
63
64 action :delete do
65   file plugin_path do
66     action :delete
67   end
68 end
69
70 action_class do
71   def plugin_path
72     "/etc/cinc/ohai/plugins/#{new_resource.plugin}.rb"
73   end
74 end