selfbootstrap 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/LICENSE +3 -0
  4. data/README.md +12 -0
  5. data/bin/selfbootstrap +10 -0
  6. data/certs/public/jimbodragon.pem +26 -0
  7. data/lib/selfbootstrap/nochef/berks.rb +108 -0
  8. data/lib/selfbootstrap/nochef/chef.rb +63 -0
  9. data/lib/selfbootstrap/nochef/chefrepo.rb +237 -0
  10. data/lib/selfbootstrap/nochef/commandline.rb +114 -0
  11. data/lib/selfbootstrap/nochef/defaultvalues.rb +258 -0
  12. data/lib/selfbootstrap/nochef/defaultworkstationresource.rb +95 -0
  13. data/lib/selfbootstrap/nochef/git.rb +128 -0
  14. data/lib/selfbootstrap/nochef/kitchen.rb +84 -0
  15. data/lib/selfbootstrap/nochef/knife.rb +95 -0
  16. data/lib/selfbootstrap/nochef/platforms.rb +54 -0
  17. data/lib/selfbootstrap/nochef/provisioners.rb +68 -0
  18. data/lib/selfbootstrap/nochef/selfbootstrap.rb +467 -0
  19. data/lib/selfbootstrap/nochef/ssh.rb +72 -0
  20. data/lib/selfbootstrap/nochef/suites.rb +46 -0
  21. data/lib/selfbootstrap/nochef/update.rb +62 -0
  22. data/lib/selfbootstrap/nochef/users.rb +106 -0
  23. data/lib/selfbootstrap/nochef/verifiers.rb +59 -0
  24. data/lib/selfbootstrap/nochef/workstation.rb +250 -0
  25. data/lib/selfbootstrap/nochef/workstationresource.rb +140 -0
  26. data/lib/selfbootstrap/nochef.rb +52 -0
  27. data/lib/selfbootstrap/withchef/chef.rb +120 -0
  28. data/lib/selfbootstrap/withchef/chefrepo.rb +84 -0
  29. data/lib/selfbootstrap/withchef/commandline.rb +40 -0
  30. data/lib/selfbootstrap/withchef/defaultvalues.rb +39 -0
  31. data/lib/selfbootstrap/withchef/git.rb +86 -0
  32. data/lib/selfbootstrap/withchef/selfbootstrap.rb +41 -0
  33. data/lib/selfbootstrap/withchef/users.rb +161 -0
  34. data/lib/selfbootstrap/withchef/workstation.rb +77 -0
  35. data/lib/selfbootstrap/withchef/workstationresource.rb +60 -0
  36. data/lib/selfbootstrap/withchef.rb +55 -0
  37. data/lib/selfbootstrap/withlogger/defaultvalues.rb +33 -0
  38. data/lib/selfbootstrap/withlogger/selfbootstrap.rb +41 -0
  39. data/lib/selfbootstrap/withlogger/workstationresource.rb +59 -0
  40. data/lib/selfbootstrap/withlogger.rb +52 -0
  41. data/lib/selfbootstrap.rb +132 -0
  42. data.tar.gz.sig +0 -0
  43. metadata +117 -0
  44. metadata.gz.sig +0 -0
@@ -0,0 +1,258 @@
1
+ # name 'Helper file for chef_workstation_initialize'
2
+ # maintainer 'Jimbo Dragon'
3
+ # maintainer_email 'jimbo_dragon@hotmail.com'
4
+ # license 'MIT'
5
+ # description 'Helper file for chef_workstation_initialize'
6
+ # version '0.1.0'
7
+ # chef_version '>= 16.6.14'
8
+ # issues_url 'https://github.com/jimbodragon/chef_workstation_initialize/issues'
9
+ # source_url 'https://github.com/jimbodragon/chef_workstation_initialize'
10
+ #
11
+ # Chef Infra Documentation
12
+ # https://docs.chef.io/libraries/
13
+ #
14
+
15
+ #
16
+ # This module name was auto-generated from the cookbook name. This name is a
17
+ # single word that starts with a capital letter and then continues to use
18
+ # camel-casing throughout the remainder of the name.
19
+ #
20
+
21
+ require 'json'
22
+ require 'date'
23
+ require 'fileutils'
24
+ require 'yaml'
25
+ require 'socket'
26
+
27
+ module ChefWorkstationInitialize
28
+ module SelfBootstrap
29
+ module NoChef
30
+ module DefaultValuesHelpers
31
+ def define_resource_requirements
32
+ end
33
+
34
+ def worklog_counter
35
+ @worklog_counter ||= 0
36
+ @worklog_counter += 1
37
+ end
38
+
39
+ def worklog(logstr)
40
+ # if skip_boostrap?
41
+ # create_chef_additionnal_dir unless ::File.exist?(workstation_logs_dir)
42
+ # ::File.open(::File.join(get_path(workstation_logs_dir), 'knife.log'), 'a+') do |file|
43
+ # file.puts logstr
44
+ # end
45
+ # els
46
+ puts("#{DateTime.now}(#{worklog_counter}):: #{logstr}\n")
47
+ end
48
+
49
+ def error_worklog(logstr)
50
+ worklog("ERROR:: #{logstr}")
51
+ end
52
+
53
+ def warning_worklog(logstr)
54
+ worklog("WARN:: #{logstr}")
55
+ end
56
+
57
+ def debug_worklog(logstr)
58
+ worklog("DEBUG:: #{logstr}")
59
+ end
60
+
61
+ def require_implement_method(method_name, *arguments)
62
+ warning_worklog("Method '#{method_name}' need to be implement from another module or class with arguments '#{arguments.join(', ')}'")
63
+ end
64
+
65
+ def get_path(dir_obj)
66
+ dir_obj.is_a?(::Dir) ? dir_obj.path : dir_obj
67
+ end
68
+
69
+ def parent_nil?(hashobject, *names)
70
+ hashobject.nil? ? true : hashobject.depth_nil?(names)
71
+ end
72
+
73
+ def default_hostname
74
+ respond_to?('node') ? node['hostname'] : Socket.gethostname
75
+ end
76
+
77
+ def default_chefzero_portrange
78
+ '48999-49999'
79
+ end
80
+
81
+ def generate_directory(dir_path)
82
+ corrected_dir_path = get_path(dir_path)
83
+ FileUtils.mkdir_p(corrected_dir_path) unless ::File.exist?(corrected_dir_path)
84
+ FileUtils.chown_R(workstation_resource[:user], workstation_resource[:group], corrected_dir_path)
85
+ FileUtils.chmod_R(0775, corrected_dir_path)
86
+ corrected_dir_path
87
+ end
88
+
89
+ def get_out_of_folder(folderpath, folder_to_get_out)
90
+ if get_path(folderpath).include?(folder_to_get_out)
91
+ get_out_of_folder(::File.dirname(folderpath))
92
+ else
93
+ folderpath
94
+ end
95
+ end
96
+
97
+ def get_out_of_cache_path(cachepath)
98
+ get_out_of_folder(cachepath, 'cache')
99
+ end
100
+
101
+ def get_out_of_local_chef_path(projectpath)
102
+ get_out_of_folder(projectpath, '.chef')
103
+ end
104
+
105
+ def search_local_project_folder(projectpath)
106
+ get_out_of_local_chef_path(get_out_of_cache_path(projectpath))
107
+ end
108
+
109
+ def check_install_dir(dir_to_check)
110
+ if ::File.basename(get_path(dir_to_check)) == project_name
111
+ search_local_project_folder(dir_to_check)
112
+ else
113
+ ::File.join(get_path(dir_to_check), project_name)
114
+ end
115
+ end
116
+
117
+ def generate_default_install_dir
118
+ generic_install_dir = '/usr/local/chef/repo'
119
+ # generate_directory default_install_dir
120
+ ::Dir.exist?(generic_install_dir) ? ::Dir.new(generic_install_dir) : generic_install_dir
121
+ end
122
+
123
+ def default_install_dir
124
+ if @workstation.nil?
125
+ working_dir = ENV['default_install_dir'].nil? ? ::Dir.getwd : ENV['default_install_dir']
126
+ install_path = search_local_project_folder(working_dir)
127
+ if ::Dir.exist?(install_path)
128
+ ::Dir.new(install_path)
129
+ else
130
+ error_worklog("Unable to get the project from '#{install_path}' while in the folder #{working_dir}")
131
+ end
132
+ # elsif respond_to?('node')
133
+ # check_install_dir ::Dir.new("/usr/local/chef/repo/#{node['infra_chef']['project_name']}")
134
+ elsif workstation_resource[:install_dir].nil?
135
+ debug_worklog('workstation defined but install_dir not define')
136
+ generate_default_install_dir
137
+ else
138
+ check_install_dir workstation_resource[:install_dir]
139
+ end
140
+ end
141
+
142
+ def analyse_object(object)
143
+ begin
144
+ debug_worklog("Analyzing object = #{object.class.name}")
145
+ rescue StandardError => exception
146
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
147
+ end
148
+ begin
149
+ debug_worklog("#{object.class.name}.methods = #{object.methods}")
150
+ debug_worklog("Empty = \n\n\n")
151
+ rescue StandardError => exception
152
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
153
+ end
154
+ begin
155
+ debug_worklog("#{object.class.name}.singleton_methods = #{object.singleton_methods}")
156
+ debug_worklog("Empty = \n\n\n")
157
+ rescue StandardError => exception
158
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
159
+ end
160
+ begin
161
+ debug_worklog("#{object.class.name}.public_constant = #{object.public_constant}")
162
+ debug_worklog("Empty = \n\n\n")
163
+ rescue StandardError => exception
164
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
165
+ end
166
+ begin
167
+ debug_worklog("#{object.class.name}.public_class_method = #{object.public_class_method}")
168
+ debug_worklog("Empty = \n\n\n")
169
+ rescue StandardError => exception
170
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
171
+ end
172
+ begin
173
+ debug_worklog("#{object.class.name}.singleton_methods = #{object.singleton_methods}")
174
+ debug_worklog("Empty = \n\n\n")
175
+ rescue StandardError => exception
176
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
177
+ end
178
+ begin
179
+ debug_worklog("#{object.class.name}.public_methods = #{object.public_methods}")
180
+ debug_worklog("Empty = \n\n\n")
181
+ rescue StandardError => exception
182
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
183
+ end
184
+ begin
185
+ debug_worklog("#{object.class.name}.included_modules = #{object.included_modules}")
186
+ debug_worklog("Empty = \n\n\n")
187
+ rescue StandardError => exception
188
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
189
+ end
190
+ begin
191
+ debug_worklog("#{object.class.name}.local_variables = #{object.local_variables}")
192
+ debug_worklog("Empty = \n\n\n")
193
+ rescue StandardError => exception
194
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
195
+ end
196
+ begin
197
+ debug_worklog("#{object.class.name}.instance_variables = #{object.instance_variables}")
198
+ debug_worklog("Empty = \n\n\n")
199
+ rescue StandardError => exception
200
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
201
+ end
202
+ begin
203
+ debug_worklog("#{object.class.name}.global_variables = #{object.global_variables}")
204
+ debug_worklog("Empty = \n\n\n")
205
+ rescue StandardError => exception
206
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
207
+ end
208
+ begin
209
+ debug_worklog("#{object.class.name}.class_variables = #{object.class_variables}")
210
+ debug_worklog("Empty = \n\n\n")
211
+ rescue StandardError => exception
212
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
213
+ end
214
+ begin
215
+ debug_worklog("#{object.class.name}.constants = #{object.constants}")
216
+ rescue StandardError => exception
217
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
218
+ end
219
+ begin
220
+ debug_worklog("#{object.class.name}.params = #{object.resource_name}")
221
+ rescue StandardError => exception
222
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
223
+ end
224
+ begin
225
+ debug_worklog("#{object.class.name}.resource_initializing = #{object.resource_initializing}")
226
+ rescue StandardError => exception
227
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
228
+ end
229
+ begin
230
+ debug_worklog("#{object.class.name}.resources = #{object.resources}")
231
+ rescue StandardError => exception
232
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
233
+ end
234
+ begin
235
+ debug_worklog("#{object.class.name}.params = #{object.params}")
236
+ rescue StandardError => exception
237
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
238
+ end
239
+ begin
240
+ debug_worklog("#{object.class.name}.find_resource(\"git_resource[YP]\") = #{object.find_resource(:git_resource, "YP")}")
241
+ rescue StandardError => exception
242
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
243
+ end
244
+ # begin
245
+ # analyse_object(object.find_resource(:git_resource, "YP"), logger)
246
+ # rescue StandardError => exception
247
+ # debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
248
+ # end
249
+ begin
250
+ debug_worklog("Chef::Provider::GitResource.public_class_method(:init_git) = #{Chef::Provider::GitResource.public_class_method(:init_git)}")
251
+ rescue StandardError => exception
252
+ debug_worklog("StandardError catch for: (#{exception.class.name}): #{exception.message}")
253
+ end
254
+ end
255
+ end
256
+ end
257
+ end
258
+ end
@@ -0,0 +1,95 @@
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
+ module ChefWorkstationInitialize
12
+ module SelfBootstrap
13
+ module NoChef
14
+ module WorkstationResourceHelpers
15
+ class DefaultWorkstationResource
16
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef
17
+
18
+ def workstation_resource_keys
19
+ @selfbootstrap_resource.keys
20
+ end
21
+
22
+ def [](key)
23
+ @selfbootstrap_resource ||= {
24
+ install_dir: ::Dir.getwd,
25
+ project_name: ::File.basename(::Dir.getwd),
26
+ cookbook_source: 'infra_chef',
27
+ project_description: nil,
28
+ environments: nil,
29
+ initial_command: nil,
30
+ cron_chef_solo_command: nil,
31
+ chef_boostrapped: nil,
32
+ environment: nil,
33
+ user: ENV['USER'],
34
+ group: ENV['GROUP'].nil? ? ENV['USER'] : ENV['GROUP'],
35
+ home: ENV['HOME'],
36
+ run_for_type: nil,
37
+ gitinfo: nil,
38
+ cron: nil,
39
+ provisioners: nil,
40
+ verifiers: nil,
41
+ platforms: nil,
42
+ suites: nil,
43
+ default_attributes: nil,
44
+ override_attributes: nil,
45
+ solo: true,
46
+ data_bag_encrypt_version: 3,
47
+ file_cache_path: '',
48
+ debug: false,
49
+ }
50
+ if @selfbootstrap_resource.key?(key.to_sym)
51
+ @selfbootstrap_resource[key.to_sym]
52
+ elsif @selfbootstrap_resource.key?(key.to_s)
53
+ @selfbootstrap_resource[key.to_s]
54
+ end
55
+ end
56
+
57
+ def get_workstation_property(property_name)
58
+ debug_worklog("Get property #{property_name}") # if property_name == 'group'
59
+ self[property_name]
60
+ end
61
+
62
+ def set_workstation_property(property_name, value)
63
+ debug_worklog("Assign property #{property_name} is value #{value.is_a?(::Dir) ? get_path(value) : value}")
64
+ self[property_name] = value
65
+ end
66
+ end
67
+ end
68
+ end
69
+ #
70
+ # Define the methods that you would like to assist the work you do in recipes,
71
+ # resources, or templates.
72
+ #
73
+ # def my_helper_method
74
+ # # help method implementation
75
+ # end
76
+ end
77
+ end
78
+
79
+ #
80
+ # The module you have defined may be extended within the recipe to grant the
81
+ # recipe the helper methods you define.
82
+ #
83
+ # Within your recipe you would write:
84
+ #
85
+ # extend ChefWorkstationInitialize::SelfbootstrapNochefDefaultworkstationresourceHelpers
86
+ #
87
+ # my_helper_method
88
+ #
89
+ # You may also add this to a single resource within a recipe:
90
+ #
91
+ # template '/etc/app.conf' do
92
+ # extend ChefWorkstationInitialize::SelfbootstrapNochefDefaultworkstationresourceHelpers
93
+ # variables specific_key: my_helper_method
94
+ # end
95
+ #
@@ -0,0 +1,128 @@
1
+ # name 'Helper file for chef_workstation_initialize'
2
+ # maintainer 'Jimbo Dragon'
3
+ # maintainer_email 'jimbo_dragon@hotmail.com'
4
+ # license 'MIT'
5
+ # description 'Helper file for chef_workstation_initialize'
6
+ # version '0.1.0'
7
+ # chef_version '>= 16.6.14'
8
+ # issues_url 'https://github.com/jimbodragon/chef_workstation_initialize/issues'
9
+ # source_url 'https://github.com/jimbodragon/chef_workstation_initialize'
10
+ #
11
+ # Chef Infra Documentation
12
+ # https://docs.chef.io/libraries/
13
+ #
14
+
15
+ #
16
+ # This module name was auto-generated from the cookbook name. This name is a
17
+ # single word that starts with a capital letter and then continues to use
18
+ # camel-casing throughout the remainder of the name.
19
+ #
20
+
21
+ require_relative 'ssh'
22
+
23
+ module ChefWorkstationInitialize
24
+ module SelfBootstrap
25
+ module NoChef
26
+ module GitHelpers
27
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef::SSHHelpers
28
+
29
+ def get_git_submodule(git_name, git_info, action, compile_time)
30
+ require_implement_method('get_git_submodule', %w(git_name git_info action compile_time))
31
+ end
32
+
33
+ def get_git_server(git_action)
34
+ require_implement_method('get_git_server', %w(git_action))
35
+ end
36
+
37
+ def git_exec(*args, **run_opts)
38
+ base_command('git', args, run_opts)
39
+ end
40
+
41
+ def git_submodule_init
42
+ git_exec('submodule' + 'init')
43
+ git_exec('submodule' + 'update')
44
+ end
45
+
46
+ def repository_list
47
+ if parent_nil?(workstation_resource, 'gitinfo', 'submodules')
48
+ worklog('Use default repository')
49
+ [project_name, "#{project_name}_generator", new_cookbook_name]
50
+ else
51
+ worklog("workstation_resource[:gitinfo][\"submodules\"] = #{JSON.pretty_generate(workstation_resource[:gitinfo]['submodules'])}")
52
+ [project_name, "#{project_name}_generator", new_cookbook_name] + workstation_resource[:gitinfo]['submodules'].keys
53
+ end
54
+ end
55
+
56
+ def all_cookbooks
57
+ cookbooks_Arr = []
58
+ workstation_resource[:gitinfo]['submodules'].each do |gitname, git_info|
59
+ case git_info['type']
60
+ when 'cookbooks', 'libraries', 'resources'
61
+ cookbooks_Arr.push(gitname)
62
+ end
63
+ end unless parent_nil?(workstation_resource[:gitinfo], 'submodules')
64
+ cookbooks_Arr
65
+ end
66
+
67
+ def get_git_relative_path(gitname)
68
+ if gitname == project_name
69
+ ''
70
+ elsif workstation_resource[:gitinfo]['submodules'][gitname].nil?
71
+ ''
72
+ else
73
+ ::File.join(workstation_resource[:gitinfo]['submodules'][gitname]['type'], gitname)
74
+ end
75
+ end
76
+
77
+ def get_git_path(gitname)
78
+ ::File.join(get_path(workstation_chef_repo_path), get_git_relative_path(gitname))
79
+ end
80
+
81
+ def get_self_git(action, compile_time)
82
+ get_git_submodule(project_name, workstation_resource[:gitinfo], action, compile_time)
83
+ end
84
+
85
+ def generate_json_repo(type, repository, revision = 'master', remote = 'origin', submodule_list = nil, additional_remotes = nil)
86
+ json_output = {
87
+ type: type,
88
+ repository: repository,
89
+ revision: revision,
90
+ remote: remote,
91
+ submodules: submodule_list,
92
+ additional_remotes: additional_remotes,
93
+ }
94
+ worklog("Generate json for #{JSON.pretty_generate(json_output)}")
95
+ json_output
96
+ end
97
+
98
+ def generate_git_submodules(modules)
99
+ json_submodules = {}
100
+ modules.each do |module_name, module_info|
101
+ json_submodules[module_name] = { path: get_git_path(module_name), repository: module_info['repository'] }
102
+ end
103
+ json_submodules
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ #
111
+ # The module you have defined may be extended within the recipe to grant the
112
+ # recipe the helper methods you define.
113
+ #
114
+ # Within your recipe you would write:
115
+ #
116
+ # extend ChefWorkstationInitialize::ChefHelpers
117
+ #
118
+ # my_helper_method
119
+ #
120
+ # You may also add this to a single resource within a recipe:
121
+ #
122
+ # template '/etc/app.conf' do
123
+ # extend ChefWorkstationInitialize::ChefHelpers
124
+ # variables specific_key: my_helper_method
125
+ # end
126
+ #
127
+
128
+ # require_relative "../providers/git_resource"
@@ -0,0 +1,84 @@
1
+ # name 'Helper file for chef_workstation_initialize'
2
+ # maintainer 'Jimbo Dragon'
3
+ # maintainer_email 'jimbo_dragon@hotmail.com'
4
+ # license 'MIT'
5
+ # description 'Helper file for chef_workstation_initialize'
6
+ # version '0.1.0'
7
+ # chef_version '>= 16.6.14'
8
+ # issues_url 'https://github.com/jimbodragon/chef_workstation_initialize/issues'
9
+ # source_url 'https://github.com/jimbodragon/chef_workstation_initialize'
10
+ #
11
+ # Chef Infra Documentation
12
+ # https://docs.chef.io/libraries/
13
+ #
14
+
15
+ #
16
+ # This module name was auto-generated from the cookbook name. This name is a
17
+ # single word that starts with a capital letter and then continues to use
18
+ # camel-casing throughout the remainder of the name.
19
+ #
20
+
21
+ require_relative 'chef'
22
+ require_relative 'provisioners'
23
+
24
+ module ChefWorkstationInitialize
25
+ module SelfBootstrap
26
+ module NoChef
27
+ module KitchenHelpers
28
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef::ChefHelpers
29
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef::ProvisionersHelpers
30
+
31
+ def kitchen(*args, **run_opts)
32
+ base_command('kitchen', args, run_opts)
33
+ end
34
+
35
+ def kitchen_root
36
+ get_path(workstation_chef_repo_path)
37
+ end
38
+
39
+ def generate_kitchen(machine_name)
40
+ kitchen_machine(machine_name, workstation_resource[:user], workstation_resource[:group], workstation_chef_repo_path)
41
+ end
42
+
43
+ def generate_machine(machine_name)
44
+ kitchen_machine(machine_name, workstation_resource[:user], workstation_resource[:group], workstation_chef_repo_path)
45
+ end
46
+
47
+ def building_kitchen
48
+ worklog 'kitchen converge'
49
+ kitchen 'converge', cwd: workstation_chef_repo_path
50
+ end
51
+
52
+ def kitchen_machine(machine_name, kitchen_user, kitchen_group, kitchen_dir)
53
+ change_unix_permission
54
+
55
+ worklog "kitchen converge #{machine_name}"
56
+ kitchen "converge #{machine_name}"
57
+
58
+ change_unix_permission
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ #
66
+ # The module you have defined may be extended within the recipe to grant the
67
+ # recipe the helper methods you define.
68
+ #
69
+ # Within your recipe you would write:
70
+ #
71
+ # extend ChefWorkstationInitialize::ChefHelpers
72
+ #
73
+ # my_helper_method
74
+ #
75
+ # You may also add this to a single resource within a recipe:
76
+ #
77
+ # template '/etc/app.conf' do
78
+ # extend ChefWorkstationInitialize::ChefHelpers
79
+ # variables specific_key: my_helper_method
80
+ # end
81
+ #
82
+
83
+ # require_relative "../providers/git_resource"
84
+
@@ -0,0 +1,95 @@
1
+ # name 'Helper file for chef_workstation_initialize'
2
+ # maintainer 'Jimbo Dragon'
3
+ # maintainer_email 'jimbo_dragon@hotmail.com'
4
+ # license 'MIT'
5
+ # description 'Helper file for chef_workstation_initialize'
6
+ # version '0.1.0'
7
+ # chef_version '>= 16.6.14'
8
+ # issues_url 'https://github.com/jimbodragon/chef_workstation_initialize/issues'
9
+ # source_url 'https://github.com/jimbodragon/chef_workstation_initialize'
10
+ #
11
+ # Chef Infra Documentation
12
+ # https://docs.chef.io/libraries/
13
+ #
14
+
15
+ #
16
+ # This module name was auto-generated from the cookbook name. This name is a
17
+ # single word that starts with a capital letter and then continues to use
18
+ # camel-casing throughout the remainder of the name.
19
+ #
20
+
21
+ require_relative 'chefrepo'
22
+
23
+ module ChefWorkstationInitialize
24
+ module SelfBootstrap
25
+ module NoChef
26
+ module KnifeHelpers
27
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef::ChefRepoHelpers
28
+
29
+ def knife(*args, **run_opts)
30
+ base_command('knife', *args, **run_opts)
31
+ end
32
+
33
+ def get_solo_cmd
34
+ worklog 'Get solo from knife'
35
+ knife 'config show solo --format json', live: true
36
+ end
37
+
38
+ def knife_search_self_cmd
39
+ knife_options = ['search']
40
+ knife_options << 'node'
41
+ knife_options << "name:#{default_hostname}"
42
+ knife_options << '--format json'
43
+ knife_options << '-z' if is_solo?
44
+ knife knife_options
45
+ end
46
+
47
+ def self_bootstrap_options
48
+ "-N #{default_hostname}"
49
+ end
50
+
51
+ def knife_get_node_attribute(nodename, attribute)
52
+ knife "node show #{nodename} -a #{attribute}"
53
+ end
54
+
55
+ def knife_self_bootstrap_cmd
56
+ knife "bootstrap #{self_bootstrap_options} --policy-group #{project_name} --policy-name #{project_name} #{default_hostname}"
57
+ end
58
+
59
+ def chef_client_self_bootstrap_cmd
60
+ chef_client_options = [self_bootstrap_options]
61
+ chef_client_options << "--runlist #{project_name}"
62
+ if ::File.exist?('solo.rb')
63
+ chef_client_options << '-c solo.rb'
64
+ else
65
+ chef_client_options << chef_solo_options_command
66
+ chef_client_options << "--chef-zero-host #{default_hostname}"
67
+ chef_client_options << "--chef-zero-port #{default_chefzero_portrange}"
68
+ end
69
+ chef_client chef_client_options, debug: true
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ #
77
+ # The module you have defined may be extended within the recipe to grant the
78
+ # recipe the helper methods you define.
79
+ #
80
+ # Within your recipe you would write:
81
+ #
82
+ # extend ChefWorkstationInitialize::ChefHelpers
83
+ #
84
+ # my_helper_method
85
+ #
86
+ # You may also add this to a single resource within a recipe:
87
+ #
88
+ # template '/etc/app.conf' do
89
+ # extend ChefWorkstationInitialize::ChefHelpers
90
+ # variables specific_key: my_helper_method
91
+ # end
92
+ #
93
+
94
+ # require_relative "../providers/git_resource"
95
+