Module: ChefWorkstationInitialize::SelfBootstrap::NoChef::ChefRepoHelpers
Instance Method Summary
collapse
#building_kitchen, #generate_kitchen, #generate_machine, #is_kitchen_command?, #kitchen, #kitchen_machine, #kitchen_root
#chef_zero_provisioner, #provisioners
#default_platforms
#default_suites
#inspec_verifier, #verifiers
#chef, #chef_client, #install_chef_workstation, #is_chef_cli_command?, #is_chef_client_command?, #is_chef_command?, #is_chef_enabled?, #is_chef_installed?, #is_chef_profile_set?, #is_chefworkstation_available?, #is_knife_gem_install?
#berks, #berks_vendor, #berks_vendor_all_cookbook, #berks_vendor_cookbook, #berks_vendor_init, #delete_all_berkslock, #delete_cookbook_berkslock, #reset_berks_vendor_dir, #self_berks_vendor
Methods included from GitHelpers
#all_cookbooks, #generate_git_submodules, #generate_json_repo, #get_git_path, #get_git_relative_path, #get_git_server, #get_git_submodule, #get_self_git, #git_exec, #git_submodule_init, #repository_list
Methods included from SSHHelpers
#delete_hostkey, #delete_hostkey_ip_or_name, #generate_private_key, #ssh, #ssh_command, #ssh_keygen
#base_command, #get_homedir, #is_mixlib_disabled?, #main_command, #run_options
#analyse_object, #check_install_dir, #debug_worklog, #default_chefzero_portrange, #default_hostname, #default_install_dir, #define_resource_requirements, #error_worklog, #generate_default_install_dir, #generate_directory, #get_out_of_cache_path, #get_out_of_folder, #get_out_of_local_chef_path, #get_path, #is_chef_constant_enabled?, #parent_nil?, #require_implement_method, #search_local_project_folder, #warning_worklog, #worklog, #worklog_counter
Instance Method Details
#create_attribute_file(cookbookname, attribute_name) ⇒ Object
131
132
133
134
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 131
def create_attribute_file(cookbookname, attribute_name)
worklog "Create attribute #{attribute_name} for #{cookbookname} in path #{get_git_path(cookbookname)}"
chef "generate attribute #{attribute_name}", cwd: get_git_path(cookbookname)
end
|
#create_chef_additionnal_dir ⇒ Object
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
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 37
def create_chef_additionnal_dir
generate_directory workstation_logs_dir
generate_directory workstation_generators_dir
generate_directory workstation_chef_repo_path
generate_directory workstation_cookbooks_dir
generate_directory workstation_libraries_dir
generate_directory workstation_resources_dir
generate_directory workstation_berks_vendor_dir
generate_directory workstation_data_bags_dir
generate_directory workstation_chef_environments_dir
generate_directory workstation_nodes_dir
generate_directory workstation_policy_group_dir
generate_directory workstation_policy_dir
generate_directory workstation_policy_files_dir
generate_directory workstation_roles_dir
generate_directory workstation_cache_options_syntaxe_path
generate_directory workstation_cache_path
generate_directory workstation_checksum_path
generate_directory workstation_acl_path
generate_directory workstation_client_d_dir
generate_directory workstation_client_key_path
generate_directory workstation_client_path
generate_directory workstation_config_d_dir
generate_directory workstation_config_dir
generate_directory workstation_container_path
generate_directory workstation_cookbook_artifact_path
generate_directory workstation_file_backup_path
generate_directory workstation_file_cache_path
generate_directory workstation_group_path
generate_directory workstation_ohai_segment_plugin_path
generate_directory workstation_solo_d_dir
generate_directory workstation_user_path
generate_directory workstation_syntax_check_cache_path
generate_directory workstation_trusted_certs_dir
reset_berks_vendor_dir
end
|
#create_chef_infra_cookbook ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 83
def create_chef_infra_cookbook
worklog("Chef Infra cookbook created: #{recipe_name} for #{cookbook_name}")
create_cookbook(new_cookbook_name)
create_recipe(new_cookbook_name, workstation_resource[:environment])
render_template("#{get_git_path(new_cookbook_name)}/recipes/#{workstation_resource[:environment]}.rb", 'default_infra_chef_recipe.erb')
create_recipe(new_cookbook_name, project_name)
render_template("#{get_git_path(new_cookbook_name)}/recipes/#{project_name}.rb", 'infra_chef_recipe_vbox.erb')
create_attribute_file(new_cookbook_name, 'default')
render_template("#{get_git_path(new_cookbook_name)}/attributes/default.rb", 'default_infra_chef_attribute.erb')
create_template_file(new_cookbook_name, 'default_infra_chef_attribute')
create_template_file(new_cookbook_name, 'default_infra_chef_recipe')
create_template_file(new_cookbook_name, 'infra_chef_recipe_vbox')
if cookbook_folder != new_cookbook_folder
worklog "Copy infra chef template for #{new_cookbook_name}"
cookbook_folder = ::File.join(::File.dirname(::File.dirname(::File.dirname(__FILE__))), cookbook_name)
template_folder = ::File.join(get_path(cookbook_folder), 'templates')
new_cookbook_folder = ::File.join(get_path(workstation_cookbooks_dir), new_cookbook_name)
new_template_folder = ::File.join(get_path(new_cookbook_folder), 'templates')
::Dir.each_child(template_folder) do |file|
::FileUtils.cp_r(::File.join(get_path(template_folder), file), ::File.join(get_path(new_template_folder), file))
end
end
worklog "Append infraClass in metadata of #{new_cookbook_name}"
unless file_exist?("#{get_git_path(new_cookbook_name)}/metadata.rb") && file_read("#{get_git_path(new_cookbook_name)}/metadata.rb").grep(/depends 'infra_chef'/).any?
::File.open("#{get_git_path(new_cookbook_name)}/metadata.rb", 'a') do |f|
f.puts "depends 'infra_chef'"
end
end
get_git_submodule(new_cookbook_name, workstation_resource[:gitinfo]['submodules'][new_cookbook_name], :push, workstation_resource[:compile_time]) unless parent_nil?(workstation_resource[:gitinfo], 'submodules', new_cookbook_name)
end
|
#create_cookbook(cookbookname) ⇒ Object
121
122
123
124
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 121
def create_cookbook(cookbookname)
worklog "Create the chef cookbook #{cookbookname}"
chef "generate cookbook #{cookbookname}", cwd: ::File.dirname(get_git_path(cookbookname))
end
|
#create_generator(generator_name) ⇒ Object
76
77
78
79
80
81
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 76
def create_generator(generator_name)
worklog "Create the chef generator #{generator_name}"
chef "generate generator #{::File.join(get_path(workstation_generators_dir), generator_name)}", cwd: workstation_generators_dir
get_git_submodule(generator_name, workstation_resource[:gitinfo]['submodules'][generator_name], :push, workstation_resource[:compile_time]) unless parent_nil?(workstation_resource[:gitinfo], 'submodules', generator_name)
end
|
#create_recipe(cookbookname, recipe_name) ⇒ Object
126
127
128
129
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 126
def create_recipe(cookbookname, recipe_name)
worklog "Create recipe #{recipe_name} for #{cookbookname} in path #{get_git_path(cookbookname)}"
chef "generate recipe #{recipe_name}", cwd: get_git_path(cookbookname)
end
|
#create_template_file(cookbookname, template_name) ⇒ Object
136
137
138
139
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 136
def create_template_file(cookbookname, template_name)
worklog "Create attribute #{template_name} for #{cookbookname} in path #{get_git_path(cookbookname)}"
chef "generate template #{template_name}", cwd: get_git_path(cookbookname)
end
|
#define_cron_job ⇒ Object
29
30
31
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 29
def define_cron_job
require_implement_method('define_cron_job', [])
end
|
#ensure_main_environment(main_role_environment) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 169
def ensure_main_environment(main_role_environment)
main_role_environment.deep_merge(
default_attributes: {
new_cookbook_name: {
project_name: project_name,
install_dir: workstation_chef_repo_path,
gitinfo: workstation_resource[:gitinfo],
},
}
)
end
|
#project_environment_json ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 155
def project_environment_json
ensure_main_environment(
name: project_name,
description: workstation_resource[:project_description],
chef_type: 'environment',
json_class: 'Chef::Environment',
default_attributes: workstation_resource[:default_attributes],
override_attributes: workstation_resource[:override_attributes],
run_list: [
new_cookbook_name,
]
)
end
|
#project_role_json ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 141
def project_role_json
ensure_main_environment(
name: project_name,
description: workstation_resource[:project_description],
chef_type: 'role',
json_class: 'Chef::Role',
default_attributes: workstation_resource[:default_attributes],
override_attributes: workstation_resource[:override_attributes],
run_list: [
new_cookbook_name,
]
)
end
|
#render_template(generated_path, source, **variables) ⇒ Object
33
34
35
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 33
def render_template(generated_path, source, **variables)
require_implement_method('render_template', %w(generated_path source action **variables))
end
|
#write_kitchen_file ⇒ Object
207
208
209
210
211
212
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 207
def write_kitchen_file
worklog "Generate policy file #{workstation_resource[:environment]}"
chef "generate policyfile #{::File.basename(workstation_policy_dir)}/#{workstation_resource[:environment]}", cwd: ::File.dirname(workstation_chef_repo_path)
worklog('Creating kitchen file')
render_template(::File.join(get_path(workstation_chef_repo_path), 'kitchen.yml'), 'kitchen.yml.erb', workstation: self)
end
|
#write_main_environment ⇒ Object
191
192
193
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 191
def write_main_environment
write_role_environment(workstation_chef_environments_dir, workstation_resource[:environment], project_environment_json)
end
|
#write_main_role ⇒ Object
187
188
189
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 187
def write_main_role
write_role_environment(workstation_roles_dir, project_name, project_role_json)
end
|
#write_main_role_environment ⇒ Object
195
196
197
198
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 195
def write_main_role_environment
write_main_role
write_main_environment
end
|
#write_role_environment(path, environment, project_json) ⇒ Object
181
182
183
184
185
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 181
def write_role_environment(path, environment, project_json)
file ::File.join(get_path(path), "#{environment}.json") do
content JSON.pretty_generate(project_json)
end
end
|
#write_Solo_file ⇒ Object
200
201
202
203
204
205
|
# File 'lib/selfbootstrap/nochef/chefrepo.rb', line 200
def write_Solo_file
render_template(::File.join(get_path(workstation_chef_repo_path), 'solo.rb'), 'solo.rb.erb', workstation: self)
render_template(::File.join(get_path(workstation_chef_repo_path), 'knife.rb'), 'knife.rb.erb', workstation: self)
render_template(::File.join(get_path(workstation_chef_repo_path), '.gitignore'), 'gitignore.erb', workstation: self)
render_template(::File.join(get_path(workstation_chef_repo_path), 'chefignore'), 'chefignore.erb', workstation: self)
end
|