Skip to content

Commit de53043

Browse files
Using configuration directory
Signed-off-by: Russell Seymour <[email protected]>
1 parent 3c8b333 commit de53043

File tree

11 files changed

+76
-15
lines changed

11 files changed

+76
-15
lines changed

cookbooks/camsa/attributes/chefserver.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@
2525
default['camsa']['chefserver']['user']['statsd'] = 'statsd'
2626

2727
# Set the path to the statsd js
28-
default['camsa']['chefserver']['statsd']['location'] = '/usr/local/lib/node_modules/statsd/stats.js'
28+
default['camsa']['chefserver']['statsd']['location'] = '/usr/local/lib/node_modules/statsd/stats.js'
29+
30+
default['camsa']['chefserver']['file']['config'] = '/etc/opscode/chef-server.rb'
31+
default['camsa']['chefserver']['dir']['config'] = '/etc/opscode/conf.d'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Determine the current directory
2+
current_dir = File.expand_path(File.dirname(__FILE__))
3+
4+
# Read in any configuration files in the conf.d, if it exists
5+
conf_d_dir = File.join(current_dir, 'conf.d')
6+
if File.exist?(conf_d_dir)
7+
Dir.glob(File.join(conf_d_dir), "*.rb")).each do |conf|
8+
Chef::Config.from_file(conf)
9+
end
10+
end

cookbooks/camsa/libraries/chefserver_datacollector.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def create_secret
100100
end
101101

102102
# Update the configuration file with these settings
103+
=begin
103104
open('/etc/opscode/chef-server.rb', 'a') do |f|
104105
f.puts ''
105106
f.puts '# Setting data collector for Automate server'
@@ -108,6 +109,14 @@ def create_secret
108109
f.puts '# Setup access to CIS profiles in the Automate server'
109110
f.puts "profiles['root_url'] = 'https://%s'" % [node.run_state[:http_data]['automate_fqdn']]
110111
end
112+
=end
113+
114+
template ::File.join(node['camsa']['chefserver']['dir']['config'], 'datacollector.rb') do
115+
source 'datacollector.rb'
116+
variables ({
117+
automate_fqdn: lazy { node.run_state[:http_data]['automate_fqdn'] }
118+
})
119+
end
111120
end
112121
end
113122
end

cookbooks/camsa/libraries/chefserver_ssl.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ class ChefServerSSL < CAMSABase
2020
# Only proceed if the certificate and key file exist
2121
if ::File.exist?(new_resource.cert_path) && ::File.exist?(new_resource.cert_key_path)
2222

23+
template ::File.join(node['camsa']['chefserver']['dir']['config'], 'chefssl.rb') do
24+
source 'chefssl.rb'
25+
variables({
26+
cert_path: new_resource.cert_path,
27+
cert_key_path: new_resource.cert_key_path
28+
})
29+
end
30+
31+
=begin
2332
append_if_no_line "ssl_certificate" do
2433
path new_resource.cert_path
2534
line 'echo nginx["ssl_certificate"] = "%s"' % [new_resource.cert_path]
@@ -34,6 +43,7 @@ class ChefServerSSL < CAMSABase
3443
code "chef-server-ctl reconfigure"
3544
subscribes :run, "file[#{new_resource.config_file}]", :immediately
3645
end
46+
=end
3747
end
3848
end
3949
end

cookbooks/camsa/recipes/certificate.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,4 @@
4242
automate_ssl 'ssl_patch' do
4343
only_if { node['camsa']['managed_app'] && node['camsa']['deploy']['automate'] }
4444
end
45-
46-
chefserver_ssl 'ssl_certificate' do
47-
only_if { node['camsa']['managed_app'] && !node['camsa']['deploy']['automate'] && node['camsa']['deploy']['chefserver'] }
48-
end
4945
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Recipe to configure the chef server when it is run as a separate machine
3+
#
4+
5+
if !node['camsa']['deploy']['automate'] &&
6+
node['camsa']['deploy']['chefserver']
7+
8+
camsa_config_store 'automate_fqdn' do
9+
action :retrieve
10+
end
11+
12+
directory node['camsa']['chefserver']['dir']['config'] do
13+
recursive true
14+
end
15+
16+
# Write out the configuration file that will read all files in from the config dir
17+
cookbook_file node['camsa']['chefserver']['file']['config'] do
18+
source 'chef-server.rb'
19+
end
20+
21+
chefserver_datacollector 'chef_automate_token' do
22+
recursive true
23+
24+
notifies :run, 'bash[chef_reconfigure]', :delayed
25+
end
26+
27+
chefserver_ssl 'ssl_certificate' do
28+
notifies :run, 'bash[chef_reconfigure]', :delayed
29+
end
30+
31+
32+
end

cookbooks/camsa/recipes/install.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@
140140
action :install
141141
source target
142142

143-
notifies :run, "bash[initial_chef_infra_server_config]", :immediately
143+
notifies :run, "bash[chef_reconfigure]", :immediately
144144
end
145145

146146
# Run command to install chef infra server
147-
bash 'initial_chef_infra_server_config' do
147+
bash 'chef_reconfigure' do
148148
code "chef-server-ctl reconfigure"
149149
environment ({
150150
CHEF_LICENSE: "accept"

cookbooks/camsa/recipes/integrate.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Configure SSL key and cert for Chef Server
2+
nginx["ssl_certificate"] = "<%= @cert_path %>"
3+
nginx["ssl_certificate_key"] = "<%= @cert_key_path %>"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Setting data collector for the Automate server
2+
data_collector['root_url'] = "https://<%= @automate_fqdn %>/v0/"
3+
4+
# Setup path to the CIS profiles in the Automate server
5+
profiles['root_url'] = "https://<%= @automate_fqdn %>"

0 commit comments

Comments
 (0)