-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathsetup_shclustering.rb
100 lines (89 loc) · 3.32 KB
/
setup_shclustering.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#
# Cookbook:: splunk
# Recipe:: setup_shclustering
#
# Author: Ryan LeViseur <[email protected]>
# Copyright:: (c) 2014, Chef Software, Inc <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
unless node['splunk']['shclustering']['enabled']
Chef::Log.debug('The chef-splunk::setup_shclustering recipe was added to the node,')
Chef::Log.debug('but the attribute to enable search head clustering was not set.')
return
end
# ensure that the splunk service resource is available without cloning
# the resource (CHEF-3694). this is so the later notification works,
# especially when using chefspec to run this cookbook's specs.
begin
resources('service[splunk]')
rescue Chef::Exceptions::ResourceNotFound
service 'splunk'
end
include_recipe 'chef-vault'
passwords = chef_vault_item('vault', "splunk_#{node.chef_environment}")
splunk_auth_info = passwords['auth']
shcluster_secret = passwords['secret']
# create app directories to house our server.conf with our shcluster configuration
shcluster_app_dir = "#{splunk_dir}/etc/apps/0_autogen_shcluster_config"
directory shcluster_app_dir do
owner splunk_runas_user
group splunk_runas_user
mode '755'
end
directory "#{shcluster_app_dir}/local" do
owner splunk_runas_user
group splunk_runas_user
mode '755'
end
template "#{shcluster_app_dir}/local/server.conf" do # ~FC033
source 'shclustering/server.conf.erb'
mode '600'
owner splunk_runas_user
group splunk_runas_user
variables(
shcluster_params: node['splunk']['shclustering'],
shcluster_secret: shcluster_secret
)
sensitive true
notifies :restart, 'service[splunk]', :immediately
end
# bootstrap the shcluster and elect a captain if initial_captain set to true and this is the initial shcluster build
shcluster_servers_list = node['splunk']['shclustering']['shcluster_members']
# unless shcluster members are staticly assigned via the node attribute,
# try to find the other shcluster members via Chef search
if node['splunk']['shclustering']['mode'] == 'captain' &&
node['splunk']['shclustering']['shcluster_members'].empty?
search( # ~FC003
:node,
"\
splunk_shclustering_enabled:true AND \
splunk_shclustering_label:#{node['splunk']['shclustering']['label']} AND \
chef_environment:#{node.chef_environment}"
).each do |result|
shcluster_servers_list << result['splunk']['shclustering']['mgmt_uri']
end
end
execute 'bootstrap-shcluster' do
command "#{splunk_cmd} bootstrap shcluster-captain -servers_list '#{shcluster_servers_list.join(';')}' -auth '#{splunk_auth_info}'"
sensitive true
not_if { ::File.exist?("#{splunk_dir}/etc/.setup_shcluster") }
only_if { node['splunk']['shclustering']['mode'] == 'captain' }
notifies :restart, 'service[splunk]'
end
file "#{splunk_dir}/etc/.setup_shcluster" do
content 'true\n'
owner splunk_runas_user
group splunk_runas_user
mode '600'
end