This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
/
sh_cluster.rb
47 lines (39 loc) · 1.68 KB
/
sh_cluster.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
# coding: UTF-8
# Cookbook Name:: cerner_splunk
# Provider:: sh_cluster
#
use_inline_resources
action :initialize do
search_heads = new_resource.search_heads
admin_password = new_resource.admin_password
execute 'Captain assignment' do # ~FC009
command "#{node['splunk']['cmd']} bootstrap shcluster-captain -servers_list '#{search_heads.join(',')}' -auth admin:#{admin_password}"
environment 'HOME' => node['splunk']['home']
# execute only if there isn't a captain in the cluster
not_if "#{node['splunk']['cmd']} list shcluster-members -auth admin:#{admin_password} | grep is_captain:1"
sensitive true
end
end
action :add do
search_heads = new_resource.search_heads
admin_password = new_resource.admin_password
management_host = CernerSplunk.management_host(node)
execute 'add search head' do # ~FC009
command "#{node['splunk']['cmd']} add shcluster-member -current_member_uri #{search_heads.first} -auth admin:#{admin_password}"
environment 'HOME' => node['splunk']['home']
# execute only if this SH is not an existing member of the SHC
not_if "#{node['splunk']['cmd']} list shcluster-members -auth admin:#{admin_password} | grep #{management_host}"
ignore_failure true
sensitive true
end
end
action :remove do
admin_password = new_resource.admin_password
execute 'remove search head' do # ~FC009
command "#{node['splunk']['cmd']} remove shcluster-member -auth admin:#{admin_password}"
environment 'HOME' => node['splunk']['home']
# execute only if this SH is an existing member of the SHC
only_if "#{node['splunk']['cmd']} list shcluster-members -auth admin:#{admin_password} | grep #{management_host}"
sensitive true
end
end