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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8ea35f81e20b7781e516391dbd15f3447fa756b7849ac6df470c7e9414402a55
4
+ data.tar.gz: 23c6e129f5ae6b6b43b5c37d4793213a96c67384b4480f0fabcc117772977eac
5
+ SHA512:
6
+ metadata.gz: 405fe88c5d6dd78f4bf97de9bf0f642610e269ff4818fcd644e980244b7177df4b41100c5a8efacef42850d17210cb9ddaf788bdf6128c54a6976fc91b23942c
7
+ data.tar.gz: 0febafe5b16db0f2563ccf140e7dbd14c3f1ef381e1b3f22e3d614e12a2bc422270b892c72fa7cc42ca7eb61fecb14cc6557576afe158eeb4903c45816238fd0
checksums.yaml.gz.sig ADDED
Binary file
data/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Copyright 2022 The Authors
2
+
3
+ All rights reserved, do not redistribute.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # Overview
2
+
3
+ ## Repository Directories
4
+
5
+ ## Configuration
6
+
7
+ ## Next Steps
8
+
9
+ Créez votre propre Gems
10
+ https://guides.rubygems.org/make-your-own-gem/
11
+
12
+ 1. gem signin
data/bin/selfbootstrap ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # Trap interrupts to quit cleanly. See
3
+ # https://twitter.com/mitchellh/status/283014103189053442
4
+ Signal.trap('INT') { exit 1 }
5
+
6
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), %w(.. lib))
7
+ require 'rubygems' unless defined?(Gem)
8
+ require 'selfbootstrap'
9
+
10
+ ChefWorkstationInitialize::SelfBootstrap.bootstrap
@@ -0,0 +1,26 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFqaW1t
3
+ eS5wcm92ZW5jaGVyL0RDPWhvdG1haWwvREM9Y2EwHhcNMjIxMDE4MjExMjAwWhcN
4
+ MjMxMDE4MjExMjAwWjAsMSowKAYDVQQDDCFqaW1teS5wcm92ZW5jaGVyL0RDPWhv
5
+ dG1haWwvREM9Y2EwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCex0r1
6
+ ngWBVriaiIpaW08qeFeaCMqRlotYWvXA4M796ahhyE0HUAz8IfqXyZL9FU3lyOW2
7
+ AdtO8ISR0W1nwOn3hJj6KL+KDylHP0Ih3k7pI7NysaBxi3QlpWSVOw+DOJA2OsLm
8
+ W/a9ZTeRigHiLkq4ZGIYiJFw7LhZSC1onXkGXu7vjST0ZFGL75z7kg+7zVRdB8IB
9
+ LwfwU93VPlRdNSBu4D3te0A6jN+Gvh2zvAKqd5muxT2869R0AaSDDeXyn70CbQry
10
+ AgXwO62Zl0whs5SYKZT4SHTsKPPEvIaj9UXJ863/lvxUQaqvpl+w+I/JvWaBcUS5
11
+ Ym+11VgydPyPZUiJN9EsvJJw9SuxjOXFtoGBVJ5SC3bgHeN6n74c8TCoH0IzZYlE
12
+ NLdQLw673cC4PkU2TRLYd9hKkH/0br/uxFiIcKjb0NfGERjZhYNugYNPCUzeYiM7
13
+ s4azT0a9oAbTVDjObG6M1xwOstnrdJtRaYDCswjVVtusAI10kNj4pvLVndECAwEA
14
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUXwYB8v7w
15
+ YzFbhswW02omiSMDHBAwJgYDVR0RBB8wHYEbamltbXkucHJvdmVuY2hlckBob3Rt
16
+ YWlsLmNhMCYGA1UdEgQfMB2BG2ppbW15LnByb3ZlbmNoZXJAaG90bWFpbC5jYTAN
17
+ BgkqhkiG9w0BAQsFAAOCAYEAecUO+U9BJ90Lz75iwpvmHjAy8CixyATIEb1iw/t2
18
+ tKa/XYQN8gRvYPIESWI0cgeakOZjQvlv4CUAvSwNonteXEIHUqj5p4zdGYgCQyrv
19
+ XmlGFnzoYtCwXDPWBiVZ11NyKFl8g27c3JV6mNGaWoY/zbZYtifxo6Iv8l7MDpPq
20
+ BXDjxEsM3sPAjRnH5UGt8gFF+0qHPVDPrJSnrHYj2StSkD/k+YGFTkbr6QEVlzMa
21
+ oQ9rnGKTcTyuNDtwL8dI2+Ay10miwo9UYFUMcFQ6UCo6QhRfCrxiTeHd8F6Mz+2o
22
+ FR9USF33SMWVcExLE3wwJaEEh93XbEW8flLD3MkSILSXVG2yuJ0aLMPbfJFIErhy
23
+ Lx8rvDe6SWVyoIUMM8rJbzSPV2I9w9evPUTmJu8QQLNMzMaWwWJqTG93AZBAdWlY
24
+ +V3ectLBpuoKM8f/ZFMnUPA0mAv5e7J6u9IBwyNj/cy+wLOAbpPdmhoKZXCpQcno
25
+ ysBBJbi//0tgFWwC4vOaDMch
26
+ -----END CERTIFICATE-----
@@ -0,0 +1,108 @@
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 'git'
22
+
23
+ module ChefWorkstationInitialize
24
+ module SelfBootstrap
25
+ module NoChef
26
+ module BerksHelpers
27
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef::GitHelpers
28
+
29
+ def berks(*args, **run_opts)
30
+ base_command('berks', *args, **run_opts)
31
+ end
32
+
33
+ def berks_vendor_init
34
+ worklog "Berks vendor initial cookbook\n"
35
+ berks 'install'
36
+ berks 'vendor'
37
+ end
38
+
39
+ def delete_cookbook_berkslock(cookbookname)
40
+ if dir_exist(get_git_path(cookbookname))
41
+ cookbookdir = ::Dir.new(get_git_path(cookbookname))
42
+ berkslock = ::File.join(cookbookdir, 'Berksfile.lock')
43
+ ::File.delete(berkslock) if cookbookdir.include?('Berksfile.lock')
44
+ end
45
+ end
46
+
47
+ def delete_all_berkslock
48
+ all_cookbooks.each do |cookbookname|
49
+ delete_cookbook_berkslock(cookbookname)
50
+ end
51
+ end
52
+
53
+ def berks_vendor_all_cookbook
54
+ all_cookbooks.each do |cookbook|
55
+ berks_vendor_cookbook(cookbook)
56
+ end
57
+ end
58
+
59
+ def berks_vendor_cookbook(name)
60
+ berks_vendor(name, project_name, workstation_berks_vendor_dir, get_git_path(name))
61
+ end
62
+
63
+ def berks_vendor(cookbookname, project_name, berks_path, cookbook_path)
64
+ if dir_exist(cookbook_path)
65
+ worklog "Adding berks vendor of the cookbook #{cookbookname} into the chef repo #{project_name}"
66
+ berks("vendor #{berks_path}", cwd: cookbook_path) if file_exist?(::File.join(cookbook_path, 'Berksfile'))
67
+ end
68
+ end
69
+
70
+ def self_berks_vendor
71
+ berks_vendor_cookbook(new_cookbook_name)
72
+ end
73
+
74
+ def reset_berks_vendor_dir
75
+ FileUtils.rm_rf(workstation_berks_vendor_dir)
76
+ generate_directory workstation_berks_vendor_dir
77
+ end
78
+
79
+ # def remove_double_cookbooks
80
+ # all_cookbooks.each do |cookbookname|
81
+ # ::FileUtils.rm_rf(::File.join(get_path(workstation_berks_vendor_dir), cookbookname)) if ::Dir.new(workstation_berks_vendor_dir).include?(cookbookname)
82
+ # end
83
+ # end
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ #
90
+ # The module you have defined may be extended within the recipe to grant the
91
+ # recipe the helper methods you define.
92
+ #
93
+ # Within your recipe you would write:
94
+ #
95
+ # extend ChefWorkstationInitialize::ChefHelpers
96
+ #
97
+ # my_helper_method
98
+ #
99
+ # You may also add this to a single resource within a recipe:
100
+ #
101
+ # template '/etc/app.conf' do
102
+ # extend ChefWorkstationInitialize::ChefHelpers
103
+ # variables specific_key: my_helper_method
104
+ # end
105
+ #
106
+
107
+ # require_relative "../providers/git_resource"
108
+
@@ -0,0 +1,63 @@
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 'berks'
22
+
23
+ module ChefWorkstationInitialize
24
+ module SelfBootstrap
25
+ module NoChef
26
+ module ChefHelpers
27
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef::BerksHelpers
28
+
29
+ def chef(*args, **run_opts)
30
+ base_command('chef', args, run_opts)
31
+ end
32
+
33
+ def chef_client(*args, **run_opts)
34
+ base_command('chef-client', args, run_opts)
35
+ end
36
+
37
+ def is_knife_gem_install?
38
+ chef('gem list -i knife') == 'true'
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ #
46
+ # The module you have defined may be extended within the recipe to grant the
47
+ # recipe the helper methods you define.
48
+ #
49
+ # Within your recipe you would write:
50
+ #
51
+ # extend ChefWorkstationInitialize::ChefHelpers
52
+ #
53
+ # my_helper_method
54
+ #
55
+ # You may also add this to a single resource within a recipe:
56
+ #
57
+ # template '/etc/app.conf' do
58
+ # extend ChefWorkstationInitialize::ChefHelpers
59
+ # variables specific_key: my_helper_method
60
+ # end
61
+ #
62
+
63
+ # require_relative "../providers/git_resource"
@@ -0,0 +1,237 @@
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 'kitchen'
22
+
23
+ module ChefWorkstationInitialize
24
+ module SelfBootstrap
25
+ module NoChef
26
+ module ChefRepoHelpers
27
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef::KitchenHelpers
28
+
29
+ def define_cron_job
30
+ require_implement_method('define_cron_job', [])
31
+ end
32
+
33
+ def render_template(generated_path, source, **variables)
34
+ require_implement_method('render_template', %w(generated_path source action **variables))
35
+ end
36
+
37
+ def create_chef_additionnal_dir
38
+ generate_directory workstation_logs_dir
39
+ generate_directory workstation_generators_dir
40
+
41
+ generate_directory workstation_chef_repo_path
42
+ generate_directory workstation_cookbooks_dir
43
+ generate_directory workstation_libraries_dir
44
+ generate_directory workstation_resources_dir
45
+ generate_directory workstation_berks_vendor_dir
46
+ generate_directory workstation_data_bags_dir
47
+ generate_directory workstation_chef_environments_dir
48
+ generate_directory workstation_nodes_dir
49
+ generate_directory workstation_policy_group_dir
50
+ generate_directory workstation_policy_dir
51
+ generate_directory workstation_policy_files_dir
52
+ generate_directory workstation_roles_dir
53
+ generate_directory workstation_cache_options_syntaxe_path
54
+ generate_directory workstation_cache_path
55
+ generate_directory workstation_checksum_path
56
+ generate_directory workstation_acl_path
57
+ generate_directory workstation_client_d_dir
58
+ generate_directory workstation_client_key_path
59
+ generate_directory workstation_client_path
60
+ generate_directory workstation_config_d_dir
61
+ generate_directory workstation_config_dir
62
+ generate_directory workstation_container_path
63
+ generate_directory workstation_cookbook_artifact_path
64
+ generate_directory workstation_file_backup_path
65
+ generate_directory workstation_file_cache_path
66
+ generate_directory workstation_group_path
67
+ generate_directory workstation_ohai_segment_plugin_path
68
+ generate_directory workstation_solo_d_dir
69
+ generate_directory workstation_user_path
70
+ generate_directory workstation_syntax_check_cache_path
71
+ generate_directory workstation_trusted_certs_dir
72
+
73
+ reset_berks_vendor_dir
74
+ end
75
+
76
+ def create_generator(generator_name)
77
+ worklog "Create the chef generator #{generator_name}"
78
+ chef "generate generator #{::File.join(get_path(workstation_generators_dir), generator_name)}", cwd: workstation_generators_dir
79
+
80
+ 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)
81
+ end
82
+
83
+ def create_chef_infra_cookbook
84
+ worklog("Chef Infra cookbook created: #{recipe_name} for #{cookbook_name}")
85
+ create_cookbook(new_cookbook_name)
86
+ create_recipe(new_cookbook_name, workstation_resource[:environment])
87
+ render_template("#{get_git_path(new_cookbook_name)}/recipes/#{workstation_resource[:environment]}.rb", 'default_infra_chef_recipe.erb')
88
+
89
+ create_recipe(new_cookbook_name, project_name)
90
+ render_template("#{get_git_path(new_cookbook_name)}/recipes/#{project_name}.rb", 'infra_chef_recipe_vbox.erb')
91
+
92
+ create_attribute_file(new_cookbook_name, 'default')
93
+ render_template("#{get_git_path(new_cookbook_name)}/attributes/default.rb", 'default_infra_chef_attribute.erb')
94
+
95
+ create_template_file(new_cookbook_name, 'default_infra_chef_attribute')
96
+ create_template_file(new_cookbook_name, 'default_infra_chef_recipe')
97
+ create_template_file(new_cookbook_name, 'infra_chef_recipe_vbox')
98
+
99
+ if cookbook_folder != new_cookbook_folder
100
+ worklog "Copy infra chef template for #{new_cookbook_name}"
101
+ cookbook_folder = ::File.join(::File.dirname(::File.dirname(::File.dirname(__FILE__))), cookbook_name)
102
+ template_folder = ::File.join(get_path(cookbook_folder), 'templates')
103
+ new_cookbook_folder = ::File.join(get_path(workstation_cookbooks_dir), new_cookbook_name)
104
+ new_template_folder = ::File.join(get_path(new_cookbook_folder), 'templates')
105
+ ::Dir.each_child(template_folder) do |file|
106
+ ::FileUtils.cp_r(::File.join(get_path(template_folder), file), ::File.join(get_path(new_template_folder), file))
107
+ end
108
+ end
109
+
110
+ worklog "Append infraClass in metadata of #{new_cookbook_name}"
111
+ 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?
112
+ ::File.open("#{get_git_path(new_cookbook_name)}/metadata.rb", 'a') do |f|
113
+ f.puts "depends 'infra_chef'"
114
+ # f.puts "depends 'infraClass'"
115
+ end
116
+ end
117
+
118
+ 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)
119
+ end
120
+
121
+ def create_cookbook(cookbookname)
122
+ worklog "Create the chef cookbook #{cookbookname}"
123
+ chef "generate cookbook #{cookbookname}", cwd: ::File.dirname(get_git_path(cookbookname))
124
+ end
125
+
126
+ def create_recipe(cookbookname, recipe_name)
127
+ worklog "Create recipe #{recipe_name} for #{cookbookname} in path #{get_git_path(cookbookname)}"
128
+ chef "generate recipe #{recipe_name}", cwd: get_git_path(cookbookname)
129
+ end
130
+
131
+ def create_attribute_file(cookbookname, attribute_name)
132
+ worklog "Create attribute #{attribute_name} for #{cookbookname} in path #{get_git_path(cookbookname)}"
133
+ chef "generate attribute #{attribute_name}", cwd: get_git_path(cookbookname)
134
+ end
135
+
136
+ def create_template_file(cookbookname, template_name)
137
+ worklog "Create attribute #{template_name} for #{cookbookname} in path #{get_git_path(cookbookname)}"
138
+ chef "generate template #{template_name}", cwd: get_git_path(cookbookname)
139
+ end
140
+
141
+ def project_role_json
142
+ ensure_main_environment(
143
+ name: project_name,
144
+ description: workstation_resource[:project_description],
145
+ chef_type: 'role',
146
+ json_class: 'Chef::Role',
147
+ default_attributes: workstation_resource[:default_attributes],
148
+ override_attributes: workstation_resource[:override_attributes],
149
+ run_list: [
150
+ new_cookbook_name,
151
+ ]
152
+ )
153
+ end
154
+
155
+ def project_environment_json
156
+ ensure_main_environment(
157
+ name: project_name,
158
+ description: workstation_resource[:project_description],
159
+ chef_type: 'environment',
160
+ json_class: 'Chef::Environment',
161
+ default_attributes: workstation_resource[:default_attributes],
162
+ override_attributes: workstation_resource[:override_attributes],
163
+ run_list: [
164
+ new_cookbook_name,
165
+ ]
166
+ )
167
+ end
168
+
169
+ def ensure_main_environment(main_role_environment)
170
+ main_role_environment.deep_merge(
171
+ default_attributes: {
172
+ new_cookbook_name: {
173
+ project_name: project_name,
174
+ install_dir: workstation_chef_repo_path,
175
+ gitinfo: workstation_resource[:gitinfo],
176
+ },
177
+ }
178
+ )
179
+ end
180
+
181
+ def write_role_environment(path, environment, project_json)
182
+ file ::File.join(get_path(path), "#{environment}.json") do
183
+ content JSON.pretty_generate(project_json)
184
+ end
185
+ end
186
+
187
+ def write_main_role
188
+ write_role_environment(workstation_roles_dir, project_name, project_role_json)
189
+ end
190
+
191
+ def write_main_environment
192
+ write_role_environment(workstation_chef_environments_dir, workstation_resource[:environment], project_environment_json)
193
+ end
194
+
195
+ def write_main_role_environment
196
+ write_main_role
197
+ write_main_environment
198
+ end
199
+
200
+ def write_Solo_file
201
+ render_template(::File.join(get_path(workstation_chef_repo_path), 'solo.rb'), 'solo.rb.erb', workstation: self)
202
+ render_template(::File.join(get_path(workstation_chef_repo_path), 'knife.rb'), 'knife.rb.erb', workstation: self)
203
+ render_template(::File.join(get_path(workstation_chef_repo_path), '.gitignore'), 'gitignore.erb', workstation: self)
204
+ render_template(::File.join(get_path(workstation_chef_repo_path), 'chefignore'), 'chefignore.erb', workstation: self)
205
+ end
206
+
207
+ def write_kitchen_file
208
+ worklog "Generate policy file #{workstation_resource[:environment]}"
209
+ chef "generate policyfile #{::File.basename(workstation_policy_dir)}/#{workstation_resource[:environment]}", cwd: ::File.dirname(workstation_chef_repo_path)
210
+ worklog('Creating kitchen file')
211
+ render_template(::File.join(get_path(workstation_chef_repo_path), 'kitchen.yml'), 'kitchen.yml.erb', workstation: self)
212
+ end
213
+ end
214
+ end
215
+ end
216
+ end
217
+
218
+ #
219
+ # The module you have defined may be extended within the recipe to grant the
220
+ # recipe the helper methods you define.
221
+ #
222
+ # Within your recipe you would write:
223
+ #
224
+ # extend ChefWorkstationInitialize::ChefHelpers
225
+ #
226
+ # my_helper_method
227
+ #
228
+ # You may also add this to a single resource within a recipe:
229
+ #
230
+ # template '/etc/app.conf' do
231
+ # extend ChefWorkstationInitialize::ChefHelpers
232
+ # variables specific_key: my_helper_method
233
+ # end
234
+ #
235
+
236
+ # require_relative "../providers/git_resource"
237
+
@@ -0,0 +1,114 @@
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 'defaultvalues'
13
+
14
+ module ChefWorkstationInitialize
15
+ module SelfBootstrap
16
+ module NoChef
17
+ module CommandlineHelpers
18
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef::DefaultValuesHelpers
19
+
20
+ def main_command(command, args = [], run_opts = {})
21
+ command = 'sudo ' + command.to_s if run_opts[:sudo]
22
+ main_command = [command, args].compact.join(' ')
23
+ worklog "running \"#{main_command}\" from a shell terminal" if run_opts[:debug]
24
+ [main_command, run_options(run_opts)]
25
+ end
26
+
27
+ def base_command(command, args = [], run_opts = {})
28
+ # logger.trace "running #{chef_command}"
29
+ final_command, final_run_options = main_command(command, args, run_opts)
30
+
31
+ if respond_to?('shell_out!')
32
+ warning_worklog('Using shell_out! as executer')
33
+ [shell_out!(final_command, final_run_options)]
34
+ elsif defined?(Mixlib).nil?
35
+ error_worklog('Cannot continue without at least a Chef workstation setup to run command ' + final_command)
36
+ exit 1
37
+ else
38
+ # warning_worklog('Using Mixlib::ShellOut as executer')
39
+ shell_command = Mixlib::ShellOut.new(final_command, final_run_options)
40
+ shell_command.run_command
41
+ # worklog shell_command.inspect
42
+ # output = shell_command.stdout
43
+ # output += "\nSTDERR: #{shell_command.stderr}" unless shell_command.error?
44
+ shell_command.stdout
45
+ end
46
+ end
47
+
48
+ def run_options(run_opts = {})
49
+ # debug_worklog run_opts.inspect
50
+ env = {}
51
+ if workstation_resource[:user]
52
+ run_opts[:user] = workstation_resource[:user]
53
+ # Certain versions of `git` misbehave if git configuration is
54
+ # inaccessible in $HOME. We need to ensure $HOME matches the
55
+ # user who is executing `git` not the user running Chef.
56
+ env['HOME'] = get_homedir(workstation_resource[:user])
57
+ end
58
+ livestream = run_opts[:live].nil? || run_opts[:live]
59
+ run_opts[:group] = workstation_resource[:group] if workstation_resource[:group]
60
+ env['GIT_SSH'] = workstation_resource[:ssh_wrapper] if workstation_resource[:ssh_wrapper]
61
+ run_opts[:log_tag] = workstation_resource[:log_tag] if workstation_resource[:log_tag]
62
+ run_opts[:timeout] = workstation_resource[:timeout] if workstation_resource[:timeout]
63
+ env.merge!(workstation_resource[:environment_variables]) if workstation_resource[:environment_variables]
64
+ run_opts[:environment] = env unless env.empty?
65
+ run_opts[:live_stream] = $stdout if livestream
66
+ run_opts.delete :sudo if run_opts.key? :sudo
67
+ run_opts.delete :live if run_opts.key? :live
68
+ run_opts.delete :debug if run_opts.key? :debug
69
+ run_opts
70
+ end
71
+
72
+ # Returns the home directory of the user
73
+ # @param [String] user must be a string.
74
+ # @return [String] the home directory of the user.
75
+ # from @Chef_16.6.14/provider/git
76
+ #
77
+ def get_homedir(user)
78
+ require 'etc' unless defined?(Etc)
79
+ case user
80
+ when Integer
81
+ Etc.getpwuid(user).dir
82
+ else
83
+ Etc.getpwnam(user.to_s).dir
84
+ end
85
+ end
86
+ #
87
+ # Define the methods that you would like to assist the work you do in recipes,
88
+ # resources, or templates.
89
+ #
90
+ # def my_helper_method
91
+ # # help method implementation
92
+ # end
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ #
99
+ # The module you have defined may be extended within the recipe to grant the
100
+ # recipe the helper methods you define.
101
+ #
102
+ # Within your recipe you would write:
103
+ #
104
+ # extend ChefWorkstationInitialize::CommandlineHelpers
105
+ #
106
+ # my_helper_method
107
+ #
108
+ # You may also add this to a single resource within a recipe:
109
+ #
110
+ # template '/etc/app.conf' do
111
+ # extend ChefWorkstationInitialize::CommandlineHelpers
112
+ # variables specific_key: my_helper_method
113
+ # end
114
+ #