selfbootstrap 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/LICENSE +3 -0
- data/README.md +12 -0
- data/bin/selfbootstrap +10 -0
- data/certs/public/jimbodragon.pem +26 -0
- data/lib/selfbootstrap/nochef/berks.rb +108 -0
- data/lib/selfbootstrap/nochef/chef.rb +63 -0
- data/lib/selfbootstrap/nochef/chefrepo.rb +237 -0
- data/lib/selfbootstrap/nochef/commandline.rb +114 -0
- data/lib/selfbootstrap/nochef/defaultvalues.rb +258 -0
- data/lib/selfbootstrap/nochef/defaultworkstationresource.rb +95 -0
- data/lib/selfbootstrap/nochef/git.rb +128 -0
- data/lib/selfbootstrap/nochef/kitchen.rb +84 -0
- data/lib/selfbootstrap/nochef/knife.rb +95 -0
- data/lib/selfbootstrap/nochef/platforms.rb +54 -0
- data/lib/selfbootstrap/nochef/provisioners.rb +68 -0
- data/lib/selfbootstrap/nochef/selfbootstrap.rb +467 -0
- data/lib/selfbootstrap/nochef/ssh.rb +72 -0
- data/lib/selfbootstrap/nochef/suites.rb +46 -0
- data/lib/selfbootstrap/nochef/update.rb +62 -0
- data/lib/selfbootstrap/nochef/users.rb +106 -0
- data/lib/selfbootstrap/nochef/verifiers.rb +59 -0
- data/lib/selfbootstrap/nochef/workstation.rb +250 -0
- data/lib/selfbootstrap/nochef/workstationresource.rb +140 -0
- data/lib/selfbootstrap/nochef.rb +52 -0
- data/lib/selfbootstrap/withchef/chef.rb +120 -0
- data/lib/selfbootstrap/withchef/chefrepo.rb +84 -0
- data/lib/selfbootstrap/withchef/commandline.rb +40 -0
- data/lib/selfbootstrap/withchef/defaultvalues.rb +39 -0
- data/lib/selfbootstrap/withchef/git.rb +86 -0
- data/lib/selfbootstrap/withchef/selfbootstrap.rb +41 -0
- data/lib/selfbootstrap/withchef/users.rb +161 -0
- data/lib/selfbootstrap/withchef/workstation.rb +77 -0
- data/lib/selfbootstrap/withchef/workstationresource.rb +60 -0
- data/lib/selfbootstrap/withchef.rb +55 -0
- data/lib/selfbootstrap/withlogger/defaultvalues.rb +33 -0
- data/lib/selfbootstrap/withlogger/selfbootstrap.rb +41 -0
- data/lib/selfbootstrap/withlogger/workstationresource.rb +59 -0
- data/lib/selfbootstrap/withlogger.rb +52 -0
- data/lib/selfbootstrap.rb +132 -0
- data.tar.gz.sig +0 -0
- metadata +117 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
#
|
2
|
+
# Chef Infra Documentation
|
3
|
+
# https://docs.chef.io/libraries/
|
4
|
+
#
|
5
|
+
|
6
|
+
#
|
7
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
8
|
+
# single word that starts with a capital letter and then continues to use
|
9
|
+
# camel-casing throughout the remainder of the name.
|
10
|
+
#
|
11
|
+
|
12
|
+
require_relative 'suites'
|
13
|
+
|
14
|
+
module ChefWorkstationInitialize
|
15
|
+
module SelfBootstrap
|
16
|
+
module NoChef
|
17
|
+
module PlatformsHelpers
|
18
|
+
include ChefWorkstationInitialize::SelfBootstrap::NoChef::SuitesHelpers
|
19
|
+
#
|
20
|
+
# Define the methods that you would like to assist the work you do in recipes,
|
21
|
+
# resources, or templates.
|
22
|
+
#
|
23
|
+
# def my_helper_method
|
24
|
+
# worklog('Running method my_helper_method' + " for class #{self.class} inside file #{__FILE__}")
|
25
|
+
|
26
|
+
# # help method implementation
|
27
|
+
# end
|
28
|
+
def default_platforms
|
29
|
+
worklog('Running method default_platforms' + " for class #{self.class} inside file #{__FILE__}")
|
30
|
+
|
31
|
+
workstation_resource[:platforms]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# The module you have defined may be extended within the recipe to grant the
|
40
|
+
# recipe the helper methods you define.
|
41
|
+
#
|
42
|
+
# Within your recipe you would write:
|
43
|
+
#
|
44
|
+
# extend ChefWorkstationInitialize::PlatformsHelpers
|
45
|
+
#
|
46
|
+
# my_helper_method
|
47
|
+
#
|
48
|
+
# You may also add this to a single resource within a recipe:
|
49
|
+
#
|
50
|
+
# template '/etc/app.conf' do
|
51
|
+
# extend ChefWorkstationInitialize::PlatformsHelpers
|
52
|
+
# variables specific_key: my_helper_method
|
53
|
+
# end
|
54
|
+
#
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#
|
2
|
+
# Chef Infra Documentation
|
3
|
+
# https://docs.chef.io/libraries/
|
4
|
+
#
|
5
|
+
|
6
|
+
#
|
7
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
8
|
+
# single word that starts with a capital letter and then continues to use
|
9
|
+
# camel-casing throughout the remainder of the name.
|
10
|
+
#
|
11
|
+
|
12
|
+
require_relative 'verifiers'
|
13
|
+
require_relative 'platforms'
|
14
|
+
|
15
|
+
module ChefWorkstationInitialize
|
16
|
+
module SelfBootstrap
|
17
|
+
module NoChef
|
18
|
+
module ProvisionersHelpers
|
19
|
+
include ChefWorkstationInitialize::SelfBootstrap::NoChef::VerifiersHelpers
|
20
|
+
include ChefWorkstationInitialize::SelfBootstrap::NoChef::PlatformsHelpers
|
21
|
+
#
|
22
|
+
# Define the methods that you would like to assist the work you do in recipes,
|
23
|
+
# resources, or templates.
|
24
|
+
#
|
25
|
+
# def my_helper_method
|
26
|
+
# worklog('Running method my_helper_method' + " for class #{self.class} inside file #{__FILE__}")
|
27
|
+
|
28
|
+
# # help method implementation
|
29
|
+
# end
|
30
|
+
|
31
|
+
def provisioners
|
32
|
+
worklog('Running method provisioners' + " for class #{self.class} inside file #{__FILE__}")
|
33
|
+
|
34
|
+
[chef_zero_provisioner]
|
35
|
+
end
|
36
|
+
|
37
|
+
def chef_zero_provisioner
|
38
|
+
worklog('Running method chef_zero_provisioner' + " for class #{self.class} inside file #{__FILE__}")
|
39
|
+
|
40
|
+
{
|
41
|
+
name: 'chef_zero',
|
42
|
+
always_update_cookbooks: true,
|
43
|
+
kitchen_root: kitchen_root,
|
44
|
+
# encrypted_data_bag_secret_key_path:,
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# The module you have defined may be extended within the recipe to grant the
|
54
|
+
# recipe the helper methods you define.
|
55
|
+
#
|
56
|
+
# Within your recipe you would write:
|
57
|
+
#
|
58
|
+
# extend ChefWorkstationInitialize::ProvisionersHelpers
|
59
|
+
#
|
60
|
+
# my_helper_method
|
61
|
+
#
|
62
|
+
# You may also add this to a single resource within a recipe:
|
63
|
+
#
|
64
|
+
# template '/etc/app.conf' do
|
65
|
+
# extend ChefWorkstationInitialize::ProvisionersHelpers
|
66
|
+
# variables specific_key: my_helper_method
|
67
|
+
# end
|
68
|
+
#
|
@@ -0,0 +1,467 @@
|
|
1
|
+
#
|
2
|
+
# Chef Infra Documentation
|
3
|
+
# https://docs.chef.io/libraries/
|
4
|
+
#
|
5
|
+
|
6
|
+
#
|
7
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
8
|
+
# single word that starts with a capital letter and then continues to use
|
9
|
+
# camel-casing throughout the remainder of the name.
|
10
|
+
#
|
11
|
+
|
12
|
+
require_relative 'workstationresource'
|
13
|
+
|
14
|
+
module ChefWorkstationInitialize
|
15
|
+
module SelfBootstrap
|
16
|
+
module NoChef
|
17
|
+
module SelfBootstrapHelpers
|
18
|
+
include ChefWorkstationInitialize::SelfBootstrap::NoChef::WorkstationResourceHelpers
|
19
|
+
|
20
|
+
attr_accessor :force_solo
|
21
|
+
|
22
|
+
def self_bootstrap_with_kitchen
|
23
|
+
kitchen 'list bootstrap self', sudo: true
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_chef_profile
|
27
|
+
bash_file = '/etc/bash.bashrc.copy'
|
28
|
+
chef_shell_cmd = 'eval "$(chef shell-init bash)"'
|
29
|
+
debug_worklog "Set chef profile tpo #{bash_file}"
|
30
|
+
open(bash_file, 'a') do |f|
|
31
|
+
f.puts chef_shell_cmd
|
32
|
+
end unless ::File.read(bash_file).include?(chef_shell_cmd)
|
33
|
+
end
|
34
|
+
|
35
|
+
def install_chef_client
|
36
|
+
base_command('curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -s once -P chef-workstation')
|
37
|
+
end
|
38
|
+
|
39
|
+
def is_chef_installed?
|
40
|
+
::Dir.exist?('/opt/chef-workstation')
|
41
|
+
end
|
42
|
+
|
43
|
+
def is_chef_profile_set?
|
44
|
+
base_command('which ruby') == '/usr/bin/chef-client'
|
45
|
+
end
|
46
|
+
|
47
|
+
def is_knife?
|
48
|
+
::File.basename($PROGRAM_NAME).eql?('knife')
|
49
|
+
end
|
50
|
+
|
51
|
+
def for_solo?
|
52
|
+
is_knife? && ARGV.join(' ').include?('config show solo --format json')
|
53
|
+
end
|
54
|
+
|
55
|
+
def for_search_local_node?
|
56
|
+
is_knife? && ARGV.join(' ').include?("search node name:#{default_hostname} --format json -z")
|
57
|
+
end
|
58
|
+
|
59
|
+
def is_self_bootsrapping?
|
60
|
+
is_kitchen_command? && ARGV.join(' ').include?('list bootstrap self')
|
61
|
+
end
|
62
|
+
|
63
|
+
def is_boostrapping?
|
64
|
+
# debug_worklog "unauthorized_to_boostrap = #{bootstrapping_progress_file}"
|
65
|
+
::File.exist?(bootstrapping_progress_file)
|
66
|
+
end
|
67
|
+
|
68
|
+
def is_chef_command?
|
69
|
+
::File.basename($PROGRAM_NAME).eql?('chef')
|
70
|
+
end
|
71
|
+
|
72
|
+
def is_chef_cli_command?
|
73
|
+
::File.basename($PROGRAM_NAME).eql?('chef-cli')
|
74
|
+
end
|
75
|
+
|
76
|
+
def is_chef_client_command?
|
77
|
+
::File.basename($PROGRAM_NAME).eql?('chef-client')
|
78
|
+
end
|
79
|
+
|
80
|
+
def is_kitchen_command?
|
81
|
+
::File.basename($PROGRAM_NAME).eql?('kitchen')
|
82
|
+
end
|
83
|
+
|
84
|
+
def unauthorized_to_boostrap?
|
85
|
+
is_chef_command? || is_chef_client_command? || is_chef_cli_command?
|
86
|
+
end
|
87
|
+
|
88
|
+
def skip_boostrap?
|
89
|
+
debug_worklog("for_solo = #{for_solo?}")
|
90
|
+
debug_worklog("for_search_local_node = #{for_search_local_node?}")
|
91
|
+
debug_worklog("is_boostrapping = #{is_boostrapping?}")
|
92
|
+
debug_worklog("unauthorized_to_boostrap = #{unauthorized_to_boostrap?}")
|
93
|
+
for_solo? || for_search_local_node? || is_boostrapping? || unauthorized_to_boostrap?
|
94
|
+
end
|
95
|
+
|
96
|
+
def chef_solo_options
|
97
|
+
solo_options.each do |opt, value|
|
98
|
+
send(opt, JSON.generate(JSON.generate(value).encode)) unless value.nil? || !respond_to?(opt)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def chef_solo_options_encode
|
103
|
+
chef_solo_options_str = ''
|
104
|
+
solo_options.each do |opt, value|
|
105
|
+
chef_solo_options_str += "#{opt} #{JSON.generate(JSON.generate(value).encode)}\n"
|
106
|
+
end
|
107
|
+
chef_solo_options_str
|
108
|
+
end
|
109
|
+
|
110
|
+
def chef_solo_options_command
|
111
|
+
solo_options.map do |opt, value|
|
112
|
+
encode_value = JSON.generate(value).encode
|
113
|
+
unless value.is_a? String
|
114
|
+
encode_value = JSON.generate(JSON.generate(value).encode)
|
115
|
+
end
|
116
|
+
"--config-option #{opt}=#{encode_value}"
|
117
|
+
end.join(' ')
|
118
|
+
end
|
119
|
+
|
120
|
+
def remove_bootstrap_file
|
121
|
+
FileUtils.rm bootstrapping_progress_file if ::File.exist?(bootstrapping_progress_file)
|
122
|
+
end
|
123
|
+
|
124
|
+
def boostrapp_once
|
125
|
+
create_chef_additionnal_dir
|
126
|
+
berks_vendor_init unless is_self_bootsrapping?
|
127
|
+
unless ::File.exist?(bootstrapping_progress_file)
|
128
|
+
FileUtils.touch bootstrapping_progress_file unless is_self_bootsrapping?
|
129
|
+
change_unix_permission if is_self_bootsrapping?
|
130
|
+
bootstrap_self_command
|
131
|
+
change_unix_permission if is_self_bootsrapping?
|
132
|
+
remove_bootstrap_file
|
133
|
+
exit 0 if is_self_bootsrapping?
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def bootstrap_self_command
|
138
|
+
if is_solo?
|
139
|
+
debug_worklog 'boostrapped with solo'
|
140
|
+
if workstation_resource[:user] != 'root'
|
141
|
+
debug_worklog 'boostrapped with solo and kitchen and root'
|
142
|
+
remove_bootstrap_file
|
143
|
+
self_bootstrap_with_kitchen
|
144
|
+
else
|
145
|
+
debug_worklog 'boostrapped with solo and chef-client'
|
146
|
+
install_chef_client
|
147
|
+
set_chef_profile
|
148
|
+
chef_client_self_bootstrap_cmd
|
149
|
+
end
|
150
|
+
else
|
151
|
+
debug_worklog 'boostrapped with chef-server and knife'
|
152
|
+
knife_self_bootstrap_cmd
|
153
|
+
end
|
154
|
+
debug_worklog 'bootstrap self command completed'
|
155
|
+
end
|
156
|
+
|
157
|
+
def bootstrap_self
|
158
|
+
# worklog "Bootstrap #{default_hostname} with skip #{skip_boostrap?}::#{boostrapped?}"
|
159
|
+
unless skip_boostrap? || boostrapped?
|
160
|
+
worklog 'machine not boostrapped'
|
161
|
+
boostrapp_once
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def is_solo?
|
166
|
+
force_solo || (
|
167
|
+
if skip_boostrap?
|
168
|
+
debug_worklog('Checking solo from workstation resource')
|
169
|
+
workstation_resource[:solo]
|
170
|
+
else
|
171
|
+
json_parse = JSON.parse(get_solo_cmd)
|
172
|
+
debug_worklog("is solo parse = #{json_parse}")
|
173
|
+
json_parse.nil? ? workstation_resource[:solo] : json_parse['solo']
|
174
|
+
end
|
175
|
+
)
|
176
|
+
end
|
177
|
+
|
178
|
+
def boostrapped?
|
179
|
+
return false if for_search_local_node?
|
180
|
+
|
181
|
+
begin
|
182
|
+
result = JSON.parse(knife_search_self_cmd)
|
183
|
+
debug_worklog('Searching result' + result.to_s)
|
184
|
+
rows = result['rows']
|
185
|
+
get_runlist = nil
|
186
|
+
rows.each do |row|
|
187
|
+
unless row['run_list'].nil?
|
188
|
+
get_runlist += row['run_list']
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
!get_runlist.nil?
|
193
|
+
rescue JSON::ParserError => json_parse_error
|
194
|
+
worklog "Force solo as not able to parse json in: #{json_parse_error.inspect}"
|
195
|
+
boostrapped = false
|
196
|
+
@force_solo = true
|
197
|
+
rescue StandardError => std_bootstrap_err
|
198
|
+
worklog "Not able to validate if bootrapped as: #{std_bootstrap_err.inspect}"
|
199
|
+
@force_solo = true
|
200
|
+
boostrapped = false
|
201
|
+
end
|
202
|
+
boostrapped
|
203
|
+
end
|
204
|
+
|
205
|
+
def solo_options
|
206
|
+
{
|
207
|
+
chef_repo_path: get_path(workstation_chef_repo_path),
|
208
|
+
cookbook_path: [
|
209
|
+
get_path(workstation_cookbooks_dir),
|
210
|
+
get_path(workstation_libraries_dir),
|
211
|
+
get_path(workstation_resources_dir),
|
212
|
+
get_path(workstation_berks_vendor_dir),
|
213
|
+
],
|
214
|
+
data_bags_path: get_path(workstation_data_bags_dir),
|
215
|
+
environment_path: get_path(workstation_chef_environments_dir),
|
216
|
+
node_path: get_path(workstation_nodes_dir),
|
217
|
+
policy_group_path: get_path(workstation_policy_group_dir),
|
218
|
+
policy_path: get_path(workstation_policy_dir),
|
219
|
+
role_path: get_path(workstation_roles_dir),
|
220
|
+
solo: is_solo?,
|
221
|
+
log_location: ::File.join(get_path(workstation_logs_dir), "#{project_name}_#{workstation_resource[:user]}.log"),
|
222
|
+
cache_options: {
|
223
|
+
path: get_path(workstation_cache_options_syntaxe_path),
|
224
|
+
},
|
225
|
+
cache_path: get_path(workstation_cache_path),
|
226
|
+
checksum_path: get_path(workstation_checksum_path),
|
227
|
+
acl_path: get_path(workstation_acl_path),
|
228
|
+
client_d_dir: get_path(workstation_client_d_dir),
|
229
|
+
client_key_path: get_path(workstation_client_key_path),
|
230
|
+
client_path: get_path(workstation_client_path),
|
231
|
+
color: true,
|
232
|
+
config_d_dir: get_path(workstation_config_d_dir),
|
233
|
+
config_dir: get_path(workstation_config_dir),
|
234
|
+
container_path: get_path(workstation_container_path),
|
235
|
+
cookbook_artifact_path: get_path(workstation_cookbook_artifact_path),
|
236
|
+
enable_reporting: false,
|
237
|
+
file_backup_path: get_path(workstation_file_backup_path),
|
238
|
+
file_cache_path: get_path(workstation_file_cache_path),
|
239
|
+
group: workstation_resource[:group],
|
240
|
+
group_path: get_path(workstation_group_path),
|
241
|
+
lockfile: ::File.join(get_path(workstation_file_cache_path), 'chef-client-running.pid'),
|
242
|
+
node_name: default_hostname,
|
243
|
+
ohai_segment_plugin_path: get_path(workstation_ohai_segment_plugin_path),
|
244
|
+
solo_d_dir: get_path(workstation_solo_d_dir),
|
245
|
+
user: workstation_resource[:user],
|
246
|
+
user_home: workstation_resource[:home],
|
247
|
+
user_path: get_path(workstation_user_path),
|
248
|
+
syntax_check_cache_path: get_path(workstation_syntax_check_cache_path),
|
249
|
+
trusted_certs_dir: get_path(workstation_trusted_certs_dir),
|
250
|
+
validation_client_name: "#{project_name}-chef-validator",
|
251
|
+
data_bag_encrypt_version: 3,
|
252
|
+
# # client_key "#{current_dir}/<%= @workstation_resource[:gitinfo]user %>.pem"
|
253
|
+
# # chef_server_url "https://chef.jimbodragon.qc.to/organizations/<%= @workstation_resource[:gitinfo]project_name %>"
|
254
|
+
# # acl_path: /root/acls,
|
255
|
+
# # allowed_automatic_attributes: nil,
|
256
|
+
# # allowed_default_attributes: nil,
|
257
|
+
# # allowed_normal_attributes: nil,
|
258
|
+
# # allowed_override_attributes: nil,
|
259
|
+
# # always_dump_stacktrace: false,
|
260
|
+
# # authentication_protocol_version: 1.1,
|
261
|
+
# # automatic_attribute_blacklist: nil,
|
262
|
+
# # automatic_attribute_whitelist: nil,
|
263
|
+
# # blocked_automatic_attributes: nil,
|
264
|
+
# # blocked_default_attributes: nil,
|
265
|
+
# # blocked_normal_attributes: nil,
|
266
|
+
# # blocked_override_attributes: nil,
|
267
|
+
# # cache_options: {
|
268
|
+
# # path: /root/.chef/syntaxcache
|
269
|
+
# # },
|
270
|
+
# # cache_path: /root/.chef/local-mode-cache,
|
271
|
+
# # checksum_path: /root/.chef/local-mode-cache/checksums,
|
272
|
+
# # chef_guid: nil,
|
273
|
+
# # chef_guid_path: /root/.chef/chef_guid,
|
274
|
+
# # chef_repo_path: /root,
|
275
|
+
# # chef_server_root: chefzero://localhost: 1,
|
276
|
+
# # chef_server_url: chefzero://localhost: 1,
|
277
|
+
# # chef_zero: {
|
278
|
+
# # enabled: true,
|
279
|
+
# # host: localhost,
|
280
|
+
# # osc_compat: false,
|
281
|
+
# # port: #<Enumerator: 0x000000000136d318>,
|
282
|
+
# # single_org: chef
|
283
|
+
# # },
|
284
|
+
# # chefcli: nil,
|
285
|
+
# # chefdk: nil,
|
286
|
+
# # clear_gem_sources: nil,
|
287
|
+
# # client_d_dir: /root/.chef/client.d,
|
288
|
+
# # client_fork: nil,
|
289
|
+
# # client_key: nil,
|
290
|
+
# # client_key_contents: nil,
|
291
|
+
# # client_key_path: /root/client_keys,
|
292
|
+
# # client_path: /root/clients,
|
293
|
+
# # client_registration_retries: 5,
|
294
|
+
# # color: true,
|
295
|
+
# # config_d_dir: /root/.chef/config.d,
|
296
|
+
# # config_dir: /root/.chef/,
|
297
|
+
# # config_file: nil,
|
298
|
+
# # container_path: /root/containers,
|
299
|
+
# # cookbook_artifact_path: /root/cookbook_artifacts,
|
300
|
+
# # cookbook_path: [
|
301
|
+
# # #{current_dir}/cookbooks,
|
302
|
+
# # #{current_dir}/libraries,
|
303
|
+
# # #{current_dir}/resources
|
304
|
+
# # ],
|
305
|
+
# # cookbook_sync_threads: 10,
|
306
|
+
# # count_log_resource_updates: false,
|
307
|
+
# # data_bag_decrypt_minimum_version: 0,
|
308
|
+
# # data_bag_encrypt_version: 3,
|
309
|
+
# # data_bags_path: /root/data_bags,
|
310
|
+
# # data_collector: {
|
311
|
+
# # mode: both,
|
312
|
+
# # organization: chef_solo,
|
313
|
+
# # raise_on_failure: false,
|
314
|
+
# # server_url: nil,
|
315
|
+
# # token: nil
|
316
|
+
# # },
|
317
|
+
# # default_attribute_blacklist: nil,
|
318
|
+
# # default_attribute_whitelist: nil,
|
319
|
+
# # deployment_group: nil,
|
320
|
+
# # diff_disabled: false,
|
321
|
+
# # diff_filesize_threshold: 10000000,
|
322
|
+
# # diff_output_threshold: 1000000,
|
323
|
+
# # disable_event_loggers: false,
|
324
|
+
# # download_progress_interval: 10,
|
325
|
+
# # enable_reporting: true,
|
326
|
+
# # enable_reporting_url_fatals: false,
|
327
|
+
# # enable_selinux_file_permission_fixup: true,
|
328
|
+
# # encrypted_data_bag_secret: nil,
|
329
|
+
# # enforce_default_paths: false,
|
330
|
+
# # enforce_path_sanity: false,
|
331
|
+
# # environment_path: /root/environments,
|
332
|
+
# # event_handlers: nil,
|
333
|
+
# # event_loggers: nil,
|
334
|
+
# # exception_handlers: nil,
|
335
|
+
# # ez: false,
|
336
|
+
# # file_atomic_update: true,
|
337
|
+
# # file_backup_path: /root/.chef/local-mode-cache/backup,
|
338
|
+
# # file_cache_path: /root/.chef/local-mode-cache/cache,
|
339
|
+
# # file_staging_uses_destdir: auto,
|
340
|
+
# # fips: false,
|
341
|
+
# # follow_client_key_symlink: false,
|
342
|
+
# # force_formatter: false,
|
343
|
+
# # force_logger: false,
|
344
|
+
# # formatter: null,
|
345
|
+
# # formatters: nil,
|
346
|
+
# # group: nil,
|
347
|
+
# # group_path: /root/groups,
|
348
|
+
# # group_valid_regex: (?-mix:^[^-+~: nil,\t\r\n\f\0]+[^: nil,\t\r\n\f\0]*$),
|
349
|
+
# # http_disable_auth_on_redirect: true,
|
350
|
+
# # http_retry_count: 5,
|
351
|
+
# # http_retry_delay: 5,
|
352
|
+
# # internal_locale: C.UTF-8,
|
353
|
+
# # interval: nil,
|
354
|
+
# # json_attribs: nil,
|
355
|
+
# # knife: {
|
356
|
+
# # hints: nil
|
357
|
+
# # },
|
358
|
+
# # listen: false,
|
359
|
+
# # local_key_generation: true,
|
360
|
+
# # local_mode: true,
|
361
|
+
# # lockfile: /root/.chef/local-mode-cache/cache/chef-client-running.pid,
|
362
|
+
# # log_level: info,
|
363
|
+
# # log_location: STDERR,
|
364
|
+
# # minimal_ohai: false,
|
365
|
+
# # named_run_list: nil,
|
366
|
+
# # no_lazy_load: true,
|
367
|
+
# # node_name: root,
|
368
|
+
# # node_path: /root/nodes,
|
369
|
+
# # normal_attribute_blacklist: nil,
|
370
|
+
# # normal_attribute_whitelist: nil,
|
371
|
+
# # ohai: {
|
372
|
+
# # critical_plugins: nil,
|
373
|
+
# # disabled_plugins: nil,
|
374
|
+
# # hints_path: /etc/chef/ohai/hints,
|
375
|
+
# # log_level: auto,
|
376
|
+
# # log_location: #<IO: 0x000000000097b7d8>,
|
377
|
+
# # optional_plugins: nil,
|
378
|
+
# # plugin: nil,
|
379
|
+
# # plugin_path: nil,
|
380
|
+
# # /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/ohai-16.6.5/lib/ohai/plugins,
|
381
|
+
# # /etc/chef/ohai/plugins,
|
382
|
+
# # run_all_plugins: false,
|
383
|
+
# # shellout_timeout: 30
|
384
|
+
# # },
|
385
|
+
# # ohai_segment_plugin_path: /root/.chef/ohai/cookbook_plugins,
|
386
|
+
# # once: nil,
|
387
|
+
# # override_attribute_blacklist: nil,
|
388
|
+
# # override_attribute_whitelist: nil,
|
389
|
+
# # pid_file: nil,
|
390
|
+
# # policy_document_native_api: true,
|
391
|
+
# # policy_group: nil,
|
392
|
+
# # policy_group_path: /root/policy_groups,
|
393
|
+
# # policy_name: nil,
|
394
|
+
# # policy_path: /root/policies,
|
395
|
+
# # profile: nil,
|
396
|
+
# # recipe_url: nil,
|
397
|
+
# # repo_mode: hosted_everything,
|
398
|
+
# # report_handlers: nil,
|
399
|
+
# # resource_unified_mode_default: false,
|
400
|
+
# # rest_timeout: 300,
|
401
|
+
# # role_path: /root/roles,
|
402
|
+
# # ruby_encoding: UTF-8,
|
403
|
+
# # rubygems_cache_enabled: false,
|
404
|
+
# # rubygems_url: nil,
|
405
|
+
# # run_lock_timeout: nil,
|
406
|
+
# # script_path: nil,
|
407
|
+
# # show_download_progress: false,
|
408
|
+
# # silence_deprecation_warnings: nil,
|
409
|
+
# # solo: false,
|
410
|
+
# # solo_d_dir: /root/.chef/solo.d,
|
411
|
+
# # solo_legacy_mode: false,
|
412
|
+
# # splay: nil,
|
413
|
+
# # ssh_agent_signing: false,
|
414
|
+
# # ssl_ca_file: nil,
|
415
|
+
# # ssl_ca_path: nil,
|
416
|
+
# # ssl_client_cert: nil,
|
417
|
+
# # ssl_client_key: nil,
|
418
|
+
# # ssl_verify_mode: verify_peer,
|
419
|
+
# # start_handlers: nil,
|
420
|
+
# # stream_execute_output: false,
|
421
|
+
# # syntax_check_cache_path: /root/.chef/syntaxcache,
|
422
|
+
# # target_mode: {
|
423
|
+
# # enabled: false,
|
424
|
+
# # protocol: ssh
|
425
|
+
# # },
|
426
|
+
# # treat_deprecation_warnings_as_errors: false,
|
427
|
+
# # trusted_certs_dir: /root/.chef/trusted_certs,
|
428
|
+
# # umask: 18,
|
429
|
+
# # user: nil,
|
430
|
+
# # user_home: /root,
|
431
|
+
# # user_path: /root/users,
|
432
|
+
# # user_valid_regex: (?-mix:^[^-+~: nil,\t\r\n\f\0]+[^: nil,\t\r\n\f\0]*$),
|
433
|
+
# # validation_client_name: chef-validator,
|
434
|
+
# # validation_key: nil,
|
435
|
+
# # validation_key_contents: nil,
|
436
|
+
# # verbose_logging: true,
|
437
|
+
# # verify_api_cert: true,
|
438
|
+
# # why_run: false,
|
439
|
+
# # windows_service: {
|
440
|
+
# # watchdog_timeout: 7200
|
441
|
+
# # },
|
442
|
+
# # zypper_check_gpg: true,
|
443
|
+
}
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
#
|
451
|
+
# The module you have defined may be extended within the recipe to grant the
|
452
|
+
# recipe the helper methods you define.
|
453
|
+
#
|
454
|
+
# Within your recipe you would write:
|
455
|
+
#
|
456
|
+
# extend ChefWorkstationInitialize::WorkstationHelpers
|
457
|
+
#
|
458
|
+
# my_helper_method
|
459
|
+
#
|
460
|
+
# You may also add this to a single resource within a recipe:
|
461
|
+
#
|
462
|
+
# template '/etc/app.conf' do
|
463
|
+
# extend ChefWorkstationInitialize::WorkstationHelpers
|
464
|
+
# variables specific_key: my_helper_method
|
465
|
+
# end
|
466
|
+
#
|
467
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# Chef Infra Documentation
|
3
|
+
# https://docs.chef.io/libraries/
|
4
|
+
#
|
5
|
+
|
6
|
+
#
|
7
|
+
# This module name was auto-generated from the cookbook name. This name is a
|
8
|
+
# single word that starts with a capital letter and then continues to use
|
9
|
+
# camel-casing throughout the remainder of the name.
|
10
|
+
#
|
11
|
+
|
12
|
+
require_relative 'commandline'
|
13
|
+
|
14
|
+
module ChefWorkstationInitialize
|
15
|
+
module SelfBootstrap
|
16
|
+
module NoChef
|
17
|
+
module SSHHelpers
|
18
|
+
include ChefWorkstationInitialize::SelfBootstrap::NoChef::CommandlineHelpers
|
19
|
+
|
20
|
+
def ssh(*args, **run_opts)
|
21
|
+
base_command('ssh', args, run_opts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def ssh_keygen(*args, **run_opts)
|
25
|
+
base_command('ssh', args, run_opts)
|
26
|
+
end
|
27
|
+
|
28
|
+
def ssh_command(ip_or_name, user, command)
|
29
|
+
worklog('Running method ssh_command(ip_or_name, user, command)' + " for class #{self.class} inside file #{__FILE__}")
|
30
|
+
|
31
|
+
ssh "-o StrictHostKeyChecking=no -l #{user} #{ip_or_name} #{command}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete_hostkey_ip_or_name(ip_or_name)
|
35
|
+
worklog('Running method delete_hostkey_ip_or_name(ip_or_name)' + " for class #{self.class} inside file #{__FILE__}")
|
36
|
+
|
37
|
+
debug_worklog 'Delete_ssh_machine_key of ' + ip_or_name.to_s
|
38
|
+
ssh_keygen "-R #{ip_or_name}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_hostkey
|
42
|
+
worklog('Running method delete_hostkey' + " for class #{self.class} inside file #{__FILE__}")
|
43
|
+
|
44
|
+
delete_hostkey_ip_or_name(node['fqdn'])
|
45
|
+
delete_hostkey_ip_or_name(node['ipaddress'])
|
46
|
+
end
|
47
|
+
|
48
|
+
def generate_private_key(privkey)
|
49
|
+
ssh_keygen "-m 'RFC4716' -N '' -P '' -f #{privkey}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# The module you have defined may be extended within the recipe to grant the
|
58
|
+
# recipe the helper methods you define.
|
59
|
+
#
|
60
|
+
# Within your recipe you would write:
|
61
|
+
#
|
62
|
+
# extend ChefWorkstationInitialize::SshHelpers
|
63
|
+
#
|
64
|
+
# my_helper_method
|
65
|
+
#
|
66
|
+
# You may also add this to a single resource within a recipe:
|
67
|
+
#
|
68
|
+
# template '/etc/app.conf' do
|
69
|
+
# extend ChefWorkstationInitialize::SshHelpers
|
70
|
+
# variables specific_key: my_helper_method
|
71
|
+
# end
|
72
|
+
#
|