selfbootstrap 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ea35f81e20b7781e516391dbd15f3447fa756b7849ac6df470c7e9414402a55
4
- data.tar.gz: 23c6e129f5ae6b6b43b5c37d4793213a96c67384b4480f0fabcc117772977eac
3
+ metadata.gz: 8739c46ccf96e927b7cc40f639e182255f07e7aea55b873f169e789f7f885985
4
+ data.tar.gz: 5bb61401af6856a5c800f9d8a19be52f1ebd6a5cc69734b3dbfd200c39b08a34
5
5
  SHA512:
6
- metadata.gz: 405fe88c5d6dd78f4bf97de9bf0f642610e269ff4818fcd644e980244b7177df4b41100c5a8efacef42850d17210cb9ddaf788bdf6128c54a6976fc91b23942c
7
- data.tar.gz: 0febafe5b16db0f2563ccf140e7dbd14c3f1ef381e1b3f22e3d614e12a2bc422270b892c72fa7cc42ca7eb61fecb14cc6557576afe158eeb4903c45816238fd0
6
+ metadata.gz: a8d1b86380929c3f71d0fc0deb3bab480712a418674183f173378c631e118b17031a172f3d791184e2b17420428a6f5b95ce520f0cc3f61492d439ea88485f84
7
+ data.tar.gz: d45e16169c93f4432ec3be3e18ee98e59da5ba9c3d29a4266417721a55f6e2d30ae49b052c706f535a2096025ce7924b9050e529faa831519ddf1b81718ee0c6
checksums.yaml.gz.sig CHANGED
Binary file
File without changes
@@ -26,6 +26,40 @@ module ChefWorkstationInitialize
26
26
  module ChefHelpers
27
27
  include ChefWorkstationInitialize::SelfBootstrap::NoChef::BerksHelpers
28
28
 
29
+ def is_chef_enabled?
30
+ is_chef_constant_enabled? :Chef
31
+ end
32
+
33
+ def is_chef_command?
34
+ ::File.basename($PROGRAM_NAME).eql?('chef')
35
+ end
36
+
37
+ def is_chef_cli_command?
38
+ ::File.basename($PROGRAM_NAME).eql?('chef-cli')
39
+ end
40
+
41
+ def is_chef_client_command?
42
+ ::File.basename($PROGRAM_NAME).eql?('chef-client')
43
+ end
44
+
45
+ def is_chef_installed?
46
+ ::Dir.exist?('/opt/chef-workstation')
47
+ end
48
+
49
+ def is_chef_profile_set?
50
+ is_chef_installed? ? (base_command('which ruby', [], as_system: true).include? '/opt/chef-workstation') : false
51
+ end
52
+
53
+ def is_chefworkstation_available?
54
+ if is_chef_profile_set?
55
+ $LOAD_PATH.select do |loaded_path|
56
+ loaded_path.include? '/opt/chef-workstation'
57
+ end.count > 0
58
+ else
59
+ false
60
+ end
61
+ end
62
+
29
63
  def chef(*args, **run_opts)
30
64
  base_command('chef', args, run_opts)
31
65
  end
@@ -37,6 +71,10 @@ module ChefWorkstationInitialize
37
71
  def is_knife_gem_install?
38
72
  chef('gem list -i knife') == 'true'
39
73
  end
74
+
75
+ def install_chef_workstation
76
+ base_command('curl -L https://omnitruck.chef.io/install.sh | bash -s -- -s once -P chef-workstation', [], as_system: true)
77
+ end
40
78
  end
41
79
  end
42
80
  end
@@ -9,18 +9,22 @@
9
9
  # camel-casing throughout the remainder of the name.
10
10
  #
11
11
 
12
- require_relative 'defaultvalues'
12
+ require_relative 'defaultmethods'
13
13
 
14
14
  module ChefWorkstationInitialize
15
15
  module SelfBootstrap
16
16
  module NoChef
17
17
  module CommandlineHelpers
18
- include ChefWorkstationInitialize::SelfBootstrap::NoChef::DefaultValuesHelpers
18
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef::DefaultMethodsHelpers
19
+
20
+ def is_mixlib_disabled?
21
+ !is_chef_constant_enabled? :Mixlib
22
+ end
19
23
 
20
24
  def main_command(command, args = [], run_opts = {})
21
25
  command = 'sudo ' + command.to_s if run_opts[:sudo]
22
26
  main_command = [command, args].compact.join(' ')
23
- worklog "running \"#{main_command}\" from a shell terminal" if run_opts[:debug]
27
+ worklog "running \"#{main_command}\" from a shell terminal" # if run_opts[:debug]
24
28
  [main_command, run_options(run_opts)]
25
29
  end
26
30
 
@@ -31,9 +35,22 @@ module ChefWorkstationInitialize
31
35
  if respond_to?('shell_out!')
32
36
  warning_worklog('Using shell_out! as executer')
33
37
  [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
38
+ elsif is_mixlib_disabled?
39
+ if run_opts[:as_system]
40
+ warning_worklog "Using system to run command #{final_command}"
41
+ exit_status = system(final_command)
42
+ if exit_status.nil?
43
+ 1
44
+ elsif exit_status.is_a?(Integer)
45
+ exit_status
46
+ else
47
+ 2
48
+ end
49
+ else
50
+ error_worklog('Cannot continue without at least a Chef workstation setup to run command ' + final_command)
51
+ restart_bootstrap
52
+ exit 1
53
+ end
37
54
  else
38
55
  # warning_worklog('Using Mixlib::ShellOut as executer')
39
56
  shell_command = Mixlib::ShellOut.new(final_command, final_run_options)
@@ -47,22 +64,7 @@ module ChefWorkstationInitialize
47
64
 
48
65
  def run_options(run_opts = {})
49
66
  # 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
67
+ run_opts[:live_stream] = $stdout if run_opts[:live]
66
68
  run_opts.delete :sudo if run_opts.key? :sudo
67
69
  run_opts.delete :live if run_opts.key? :live
68
70
  run_opts.delete :debug if run_opts.key? :debug
@@ -27,10 +27,20 @@ require 'socket'
27
27
  module ChefWorkstationInitialize
28
28
  module SelfBootstrap
29
29
  module NoChef
30
- module DefaultValuesHelpers
30
+ module DefaultMethodsHelpers
31
31
  def define_resource_requirements
32
32
  end
33
33
 
34
+ def is_chef_constant_enabled?(constant)
35
+ # if is_chefworkstation_available?
36
+ constant_defined = const_defined?(constant)
37
+ worklog "constant_defined = #{constant_defined.class} for #{constant}"
38
+ constant_defined
39
+ # else
40
+ # false
41
+ # end
42
+ end
43
+
34
44
  def worklog_counter
35
45
  @worklog_counter ||= 0
36
46
  @worklog_counter += 1
@@ -8,62 +8,86 @@
8
8
  # single word that starts with a capital letter and then continues to use
9
9
  # camel-casing throughout the remainder of the name.
10
10
  #
11
+
11
12
  module ChefWorkstationInitialize
12
13
  module SelfBootstrap
13
14
  module NoChef
14
15
  module WorkstationResourceHelpers
15
- class DefaultWorkstationResource
16
- include ChefWorkstationInitialize::SelfBootstrap::NoChef
16
+ def workstation_resource_keys
17
+ default_workstation_data.keys
18
+ end
17
19
 
18
- def workstation_resource_keys
19
- @selfbootstrap_resource.keys
20
- end
20
+ def default_workstation_data
21
+ {
22
+ install_dir: ::Dir.getwd,
23
+ project_name: ::File.basename(::Dir.getwd),
24
+ cookbook_source: 'infra_chef',
25
+ project_description: nil,
26
+ environments: nil,
27
+ initial_command: nil,
28
+ cron_chef_solo_command: nil,
29
+ chef_boostrapped: nil,
30
+ environment: nil,
31
+ user: ENV['USER'],
32
+ group: ENV['GROUP'].nil? ? ENV['USER'] : ENV['GROUP'],
33
+ home: ENV['HOME'],
34
+ run_for_type: nil,
35
+ gitinfo: nil,
36
+ cron: nil,
37
+ provisioners: nil,
38
+ verifiers: nil,
39
+ platforms: nil,
40
+ suites: nil,
41
+ default_attributes: nil,
42
+ override_attributes: nil,
43
+ solo: true,
44
+ data_bag_encrypt_version: 3,
45
+ file_cache_path: '',
46
+ debug: false,
47
+ }
48
+ end
21
49
 
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
50
+ # class DefaultWorkstationResource
51
+ # include ChefWorkstationInitialize::SelfBootstrap::NoChef
52
+ # prepend ChefWorkstationInitialize::SelfBootstrap::NoChef
56
53
 
57
- def get_workstation_property(property_name)
58
- debug_worklog("Get property #{property_name}") # if property_name == 'group'
59
- self[property_name]
60
- end
54
+ # def initialize
55
+ # config_loader = ChefConfig::WorkstationConfigLoader.new(nil)
56
+ # Chef::Config.from_file(config_loader.config_location)
57
+ # end
61
58
 
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
59
+ # def workstation_resource_keys
60
+ # @selfbootstrap_resource.keys
61
+ # end
62
+
63
+ # def [](key)
64
+ # @selfbootstrap_resource ||= default_workstation_data
65
+ # if @selfbootstrap_resource.key?(key.to_sym)
66
+ # @selfbootstrap_resource[key.to_sym]
67
+ # elsif @selfbootstrap_resource.key?(key.to_s)
68
+ # @selfbootstrap_resource[key.to_s]
69
+ # end
70
+ # end
71
+
72
+ # def get_workstation_property(property_name)
73
+ # debug_worklog("Get property #{property_name}") # if property_name == 'group'
74
+ # self[property_name]
75
+ # end
76
+
77
+ # def set_workstation_property(property_name, value)
78
+ # debug_worklog("Assign property #{property_name} is value #{value.is_a?(::Dir) ? get_path(value) : value}")
79
+ # self[property_name] = value
80
+ # end
81
+
82
+ # def render_template(generated_path, source, **variables)
83
+ # if ::File.basename(generated_path).eq?('kitchen.yml')
84
+ # worklog('Generating a new kitchen file')
85
+ # kitchen 'init'
86
+ # else
87
+ # super(generated_path, source, variables)
88
+ # end
89
+ # end
90
+ # end
67
91
  end
68
92
  end
69
93
  #
@@ -28,7 +28,12 @@ module ChefWorkstationInitialize
28
28
  include ChefWorkstationInitialize::SelfBootstrap::NoChef::ChefHelpers
29
29
  include ChefWorkstationInitialize::SelfBootstrap::NoChef::ProvisionersHelpers
30
30
 
31
+ def is_kitchen_command?
32
+ ::File.basename($PROGRAM_NAME).eql?('kitchen')
33
+ end
34
+
31
35
  def kitchen(*args, **run_opts)
36
+ write_kitchen_file unless args.eql? ['init']
32
37
  base_command('kitchen', args, run_opts)
33
38
  end
34
39
 
@@ -26,6 +26,10 @@ module ChefWorkstationInitialize
26
26
  module KnifeHelpers
27
27
  include ChefWorkstationInitialize::SelfBootstrap::NoChef::ChefRepoHelpers
28
28
 
29
+ def is_knife?
30
+ ::File.basename($PROGRAM_NAME).eql?('knife')
31
+ end
32
+
29
33
  def knife(*args, **run_opts)
30
34
  base_command('knife', *args, **run_opts)
31
35
  end
@@ -53,21 +57,9 @@ module ChefWorkstationInitialize
53
57
  end
54
58
 
55
59
  def knife_self_bootstrap_cmd
60
+ debug_worklog 'boostrapped with chef-server and knife'
56
61
  knife "bootstrap #{self_bootstrap_options} --policy-group #{project_name} --policy-name #{project_name} #{default_hostname}"
57
62
  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
63
  end
72
64
  end
73
65
  end
@@ -19,35 +19,6 @@ module ChefWorkstationInitialize
19
19
 
20
20
  attr_accessor :force_solo
21
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
22
  def for_solo?
52
23
  is_knife? && ARGV.join(' ').include?('config show solo --format json')
53
24
  end
@@ -61,36 +32,23 @@ module ChefWorkstationInitialize
61
32
  end
62
33
 
63
34
  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')
35
+ is_chef_enabled? ? ::File.exist?(bootstrapping_progress_file) : false
82
36
  end
83
37
 
84
38
  def unauthorized_to_boostrap?
85
39
  is_chef_command? || is_chef_client_command? || is_chef_cli_command?
86
40
  end
87
41
 
42
+ def run_as_root?
43
+ ENV['USER'] == 'root' # workstation_resource[:user] == 'root'
44
+ end
45
+
88
46
  def skip_boostrap?
89
47
  debug_worklog("for_solo = #{for_solo?}")
90
48
  debug_worklog("for_search_local_node = #{for_search_local_node?}")
91
- debug_worklog("is_boostrapping = #{is_boostrapping?}")
92
49
  debug_worklog("unauthorized_to_boostrap = #{unauthorized_to_boostrap?}")
93
- for_solo? || for_search_local_node? || is_boostrapping? || unauthorized_to_boostrap?
50
+ debug_worklog("is_boostrapping = #{is_boostrapping?}")
51
+ for_solo? || for_search_local_node? || unauthorized_to_boostrap? || is_boostrapping?
94
52
  end
95
53
 
96
54
  def chef_solo_options
@@ -121,6 +79,58 @@ module ChefWorkstationInitialize
121
79
  FileUtils.rm bootstrapping_progress_file if ::File.exist?(bootstrapping_progress_file)
122
80
  end
123
81
 
82
+ def install_this_gem
83
+ chef 'gem install selfbootstrap', { as_system: true }
84
+ end
85
+
86
+ def restart_bootstrap
87
+ rerun_opt = { sudo: true }
88
+ if run_as_root?
89
+ install_chef_workstation
90
+ set_chef_profile
91
+ install_this_gem
92
+ rerun_opt[:as_system] = true
93
+ end
94
+ worklog 'Self bootstrap with sudo command'
95
+ debug_worklog 'boostrapped with solo and kitchen and root'
96
+ remove_bootstrap_file
97
+ exit base_command('selfbootstrap', ARGV, rerun_opt)
98
+ # kitchen 'list bootstrap self', sudo: true
99
+ end
100
+
101
+ def set_chef_profile
102
+ bash_file = '/etc/bash.bashrc'
103
+ # chef_shell_cmd = "cd #{workstation_scripts_dir}; curl -L https://omnitruck.chef.io/install_desktop.sh | sudo bash -s -- #{project_name} #{environments.join(' ')}"
104
+ chef_shell_cmd = 'eval "$(chef shell-init bash)"'
105
+ debug_worklog "Set chef profile to #{bash_file}"
106
+ open(bash_file, 'a') do |f|
107
+ f.puts chef_shell_cmd
108
+ end unless ::File.read(bash_file).include?(chef_shell_cmd)
109
+ end
110
+
111
+ def bootstrap_self_command
112
+ if is_solo?
113
+ debug_worklog 'boostrapped with solo'
114
+ if chefworkstation_available?
115
+ if chef_enabled?
116
+ prepend ChefWorkstationInitialize::SelfBootstrap::WithChef
117
+ bootstrap_self_command
118
+ else
119
+ require 'kitchen'
120
+ require 'chef'
121
+ require 'chef/workstation_config_loader'
122
+ end
123
+ elsif run_as_root?
124
+ chef_client_self_bootstrap_cmd
125
+ else
126
+ restart_bootstrap
127
+ end
128
+ else
129
+ knife_self_bootstrap_cmd
130
+ end
131
+ debug_worklog 'bootstrap self command completed'
132
+ end
133
+
124
134
  def boostrapp_once
125
135
  create_chef_additionnal_dir
126
136
  berks_vendor_init unless is_self_bootsrapping?
@@ -134,24 +144,19 @@ module ChefWorkstationInitialize
134
144
  end
135
145
  end
136
146
 
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
147
+ def chef_client_self_bootstrap_cmd
148
+ debug_worklog 'boostrapped with solo and chef-client'
149
+
150
+ chef_client_options = [self_bootstrap_options]
151
+ chef_client_options << "--runlist #{project_name}"
152
+ if ::File.exist?('solo.rb')
153
+ chef_client_options << '-c solo.rb'
150
154
  else
151
- debug_worklog 'boostrapped with chef-server and knife'
152
- knife_self_bootstrap_cmd
155
+ chef_client_options << chef_solo_options_command
156
+ chef_client_options << "--chef-zero-host #{default_hostname}"
157
+ chef_client_options << "--chef-zero-port #{default_chefzero_portrange}"
153
158
  end
154
- debug_worklog 'bootstrap self command completed'
159
+ chef_client chef_client_options, debug: true
155
160
  end
156
161
 
157
162
  def bootstrap_self
@@ -22,7 +22,7 @@ module ChefWorkstationInitialize
22
22
  end
23
23
 
24
24
  def ssh_keygen(*args, **run_opts)
25
- base_command('ssh', args, run_opts)
25
+ base_command('ssh-keygen', args, run_opts)
26
26
  end
27
27
 
28
28
  def ssh_command(ip_or_name, user, command)
@@ -10,7 +10,7 @@
10
10
  #
11
11
 
12
12
  require_relative 'workstation'
13
- require_relative 'defaultworkstationresource'
13
+ # require_relative 'defaultworkstationresource'
14
14
 
15
15
  module ChefWorkstationInitialize
16
16
  module SelfBootstrap
@@ -18,8 +18,38 @@ module ChefWorkstationInitialize
18
18
  module WorkstationResourceHelpers
19
19
  include ChefWorkstationInitialize::SelfBootstrap::NoChef::WorkstationHelpers
20
20
 
21
- def default_workstation_resource
22
- @default_workstation_resource ||= DefaultWorkstationResource.new
21
+ def workstation_resource_keys
22
+ default_workstation_data.keys
23
+ end
24
+
25
+ def default_workstation_data
26
+ {
27
+ install_dir: ::Dir.getwd,
28
+ project_name: ::File.basename(::Dir.getwd),
29
+ cookbook_source: 'infra_chef',
30
+ project_description: nil,
31
+ environments: nil,
32
+ initial_command: nil,
33
+ cron_chef_solo_command: nil,
34
+ chef_boostrapped: nil,
35
+ environment: nil,
36
+ user: ENV['USER'],
37
+ group: ENV['GROUP'].nil? ? ENV['USER'] : ENV['GROUP'],
38
+ home: ENV['HOME'],
39
+ run_for_type: nil,
40
+ gitinfo: nil,
41
+ cron: nil,
42
+ provisioners: nil,
43
+ verifiers: nil,
44
+ platforms: nil,
45
+ suites: nil,
46
+ default_attributes: nil,
47
+ override_attributes: nil,
48
+ solo: true,
49
+ data_bag_encrypt_version: 3,
50
+ file_cache_path: '',
51
+ debug: false,
52
+ }
23
53
  end
24
54
 
25
55
  def set_workstation_resource(new_resource_set)
@@ -47,74 +77,20 @@ module ChefWorkstationInitialize
47
77
  @workstation
48
78
  end
49
79
 
50
- def workstation_resource
51
- get_workstation
52
- end
53
-
54
- def get_workstation_property(property_name)
55
- require_implement_method('get_workstation_property', %w(property_name))
80
+ def set_workstation_data(workstation_data)
81
+ # ::File.join(get_path(workstation_chef_repo_path), __FILE__.gsub(/^.*cache/), '')
82
+ # @workstation_tool = new_workstation
83
+ # include new_workstation
84
+ # @workstation = default_workstation_resource if @workstation.nil?
85
+ # swap_workstation(ChefWorkstationInitialize::SelfBootstrap::WithChef) if respond_to? 'Chef'
86
+ # @workstation
56
87
 
57
- # debug_worklog("Get property #{property_name}") # if property_name == 'group'
58
- # property = nil
59
- # viarail = nil
60
- # if respond_to?('workstation_' + property_name)
61
- # viarail = 'self workstaion'
62
- # property = send('workstation_' + property_name)
63
- # elsif property_name != 'project_name' && respond_to?(property_name + '=')
64
- # viarail = 'self'
65
- # property = send(property_name)
66
- # workstation_resource_property = workstation_resource[property_name.to_sym]
67
- # if (property.nil? && !workstation_resource_property.nil?) || (!property.nil? && !workstation_resource_property.nil?)
68
- # viarail += ' Using workstation_resource_property'
69
- # property = set_workstation_property(property_name, workstation_resource_property) if property != workstation_resource_property
70
- # elsif !property.nil? && workstation_resource_property.nil?
71
- # viarail += ' Using property'
72
- # property = set_workstation_property(property_name, property)
73
- # elsif property.nil? && workstation_resource_property.nil?
74
- # viarail += ' No property present'
75
- # worklog("Property #{property_name} is not present")
76
- # end
77
- # elsif !respond_to?('new_resource') || new_resource.nil?
78
- # viarail = 'workstation_resource'
79
- # property = workstation_resource[property_name.to_sym]
80
- # elsif new_resource.respond_to?(property_name)
81
- # viarail = 'new_resource'
82
- # property = new_resource.send(property_name)
83
- # elsif new_resource.is_a?(Hash)
84
- # viarail = 'new_resource(Hash)'
85
- # property = new_resource[property_name.to_sym]
86
- # else
87
- # viarail = 'UNKNOWN'
88
- # worklog("new_resource doesn't respond to #{property_name} :: #{new_resource.class} :: #{new_resource.methods}")
89
- # property = nil
90
- # end
91
- # debug_worklog("property #{property_name} is #{property.is_a?(::Dir) ? get_path(property) : property} via #{viarail}") # if property_name == 'group'
92
- # property
88
+ workstation_data.send(:extend, ChefWorkstationInitialize::SelfBootstrap)
89
+ workstation_data
93
90
  end
94
91
 
95
- def set_workstation_property(property_name, value)
96
- require_implement_method('set_workstation_property', %w(property_name value))
97
-
98
- # debug_worklog("Assign property #{property_name} is value #{value.is_a?(::Dir) ? get_path(value) : value}")
99
- # assign = false
100
- # if property_name != 'project_name' && respond_to?(property_name + '=')
101
- # assign = true
102
- # send(property_name + '=', value)
103
- # end
104
- # if !respond_to?('new_resource') || new_resource.nil?
105
- # assign = true
106
- # workstation_resource[property_name.to_sym] = value
107
- # end
108
- # if respond_to?('new_resource') && new_resource.respond_to?(property_name)
109
- # assign = true
110
- # new_resource.send(property_name, value)
111
- # end
112
- # if respond_to?('new_resource') && new_resource.is_a?(Hash)
113
- # assign = true
114
- # new_resource[property_name] = value
115
- # end
116
- # worklog("new_resource could not assign value '#{value}' not respond to #{property_name} :: #{new_resource.class} :: #{new_resource.methods}") unless assign
117
- # get_workstation_property(property_name)
92
+ def workstation_resource
93
+ default_workstation_data
118
94
  end
119
95
  end
120
96
  end
@@ -9,17 +9,10 @@
9
9
  # camel-casing throughout the remainder of the name.
10
10
  #
11
11
 
12
- require 'withchef'
13
12
  require_relative 'nochef/selfbootstrap'
14
13
 
15
14
  module ChefWorkstationInitialize
16
15
  module SelfBootstrap
17
- if respond_to? 'Chef'
18
- include ChefWorkstationInitialize::SelfBootstrap::WithChef
19
- else
20
- include ChefWorkstationInitialize::SelfBootstrap::NoChef
21
- end
22
-
23
16
  module NoChef
24
17
  include ChefWorkstationInitialize::SelfBootstrap::NoChef::SelfBootstrapHelpers
25
18
  #
@@ -43,19 +43,25 @@ module ChefWorkstationInitialize
43
43
  end
44
44
 
45
45
  def render_template(generated_path, source, **variables)
46
- template generated_path do
47
- extend ChefWorkstationInitialize::SelfBootstrap
48
- cookbook workstation_resource[:cookbook_source]
49
- source source
50
- variables variables
51
- end
52
- template ::File.join(get_path(workstation_chef_repo_path), 'chefignore') do
53
- extend ChefWorkstationInitialize::SelfBootstrap
54
- cookbook workstation_resource[:cookbook_source]
55
- source 'chefignore.erb'
56
- variables(workstation: self)
57
- action :create_if_missing
46
+ if respond_to? :template
47
+ template generated_path do
48
+ extend ChefWorkstationInitialize::SelfBootstrap
49
+ cookbook workstation_resource[:cookbook_source]
50
+ source source
51
+ variables variables
52
+ end
53
+ elsif ::File.basename(generated_path).include?('kitchen.yml')
54
+ kitchen 'init'
55
+ else
56
+ error_worklog "Need to be inside a Chef recipe or Chef resource to run this rendering for #{generated_path}"
58
57
  end
58
+ # template ::File.join(get_path(workstation_chef_repo_path), 'chefignore') do
59
+ # extend ChefWorkstationInitialize::SelfBootstrap
60
+ # cookbook workstation_resource[:cookbook_source]
61
+ # source 'chefignore.erb'
62
+ # variables(workstation: self)
63
+ # action :create_if_missing
64
+ # end
59
65
  end
60
66
  end
61
67
  end
@@ -81,4 +87,3 @@ end
81
87
  #
82
88
 
83
89
  # require_relative "../providers/git_resource"
84
-
@@ -9,13 +9,32 @@
9
9
  # camel-casing throughout the remainder of the name.
10
10
  #
11
11
 
12
- require_relative 'defaultvalues'
12
+ require_relative 'defaultmethods'
13
13
 
14
14
  module ChefWorkstationInitialize
15
15
  module SelfBootstrap
16
16
  module WithChef
17
17
  module CommandlineHelpers
18
- include ChefWorkstationInitialize::SelfBootstrap::WithChef::DefaultValuesHelpers
18
+ include ChefWorkstationInitialize::SelfBootstrap::WithChef::DefaultMethodsHelpers
19
+
20
+ def run_options(run_opts = {})
21
+ # debug_worklog run_opts.inspect
22
+ env = {}
23
+ if workstation_resource[:user]
24
+ run_opts[:user] = workstation_resource[:user]
25
+ # Certain versions of `git` misbehave if git configuration is
26
+ # inaccessible in $HOME. We need to ensure $HOME matches the
27
+ # user who is executing `git` not the user running Chef.
28
+ env['HOME'] = get_homedir(workstation_resource[:user])
29
+ end
30
+ run_opts[:group] = workstation_resource[:group] if workstation_resource[:group]
31
+ env['GIT_SSH'] = workstation_resource[:ssh_wrapper] if workstation_resource[:ssh_wrapper]
32
+ run_opts[:log_tag] = workstation_resource[:log_tag] if workstation_resource[:log_tag]
33
+ run_opts[:timeout] = workstation_resource[:timeout] if workstation_resource[:timeout]
34
+ env.merge!(workstation_resource[:environment_variables]) if workstation_resource[:environment_variables]
35
+ run_opts[:environment] = env unless env.empty?
36
+ super(run_opts)
37
+ end
19
38
  end
20
39
  end
21
40
  end
@@ -21,17 +21,23 @@
21
21
  module ChefWorkstationInitialize
22
22
  module SelfBootstrap
23
23
  module WithChef
24
- module DefaultValuesHelpers
24
+ module DefaultMethodsHelpers
25
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef::SelfBootstrapHelpers
26
+
25
27
  def generate_directory(dir_path)
26
- directory get_path(dir_path) do
27
- group workstation_resource[:group]
28
- mode '0775'
29
- recursive true
28
+ if respond_to? :directory
29
+ directory get_path(dir_path) do
30
+ group workstation_resource[:group]
31
+ mode '0775'
32
+ recursive true
33
+ end
34
+ else
35
+ super(dir_path)
30
36
  end
31
37
  end
32
38
 
33
39
  def worklog(logstr)
34
- Chef::Log.warn("\n\n(#{worklog_counter})WORKLOG:: #{logstr}\n\n")
40
+ ::Chef::Log.warn("(#{worklog_counter}):: #{logstr}")
35
41
  end
36
42
  end
37
43
  end
@@ -17,24 +17,35 @@ module ChefWorkstationInitialize
17
17
  module WorkstationResourceHelpers
18
18
  include ChefWorkstationInitialize::SelfBootstrap::WithChef::WorkstationHelpers
19
19
 
20
- class ChefConfigResource < ChefWorkstationInitialize::SelfBootstrap::NoChef::WorkstationResourceHelpers::DefaultWorkstationResource
21
- include ChefWorkstationInitialize::SelfBootstrap::WithChef
22
-
23
- def [](key)
24
- debug_worklog('Searching config key" ' + key.to_s + '"') unless key.to_s == 'debug'
25
- if default_workstation_resource.key?(key)
26
- default_workstation_resource[key]
27
- elsif default_workstation_resource.key?(key.to_s)
28
- default_workstation_resource[key.to_s]
29
- end
30
- end
31
- end
20
+ # class ChefConfigResource < ChefWorkstationInitialize::SelfBootstrap::NoChef::WorkstationResourceHelpers::DefaultWorkstationResource
21
+ # include ChefWorkstationInitialize::SelfBootstrap::WithChef
22
+
23
+ # def [](key)
24
+ # debug_worklog('Searching config key" ' + key.to_s + '"') unless key.to_s == 'debug'
25
+ # if default_workstation_resource.key?(key)
26
+ # default_workstation_resource[key]
27
+ # elsif default_workstation_resource.key?(key.to_s)
28
+ # default_workstation_resource[key.to_s]
29
+ # end
30
+ # end
31
+ # end
32
32
 
33
- def get_workstation
34
- debug_worklog "Get workstation from #{self.class}"
35
- @workstation = ChefConfigResource.new if @workstation.nil?
36
- swap_workstation(ChefWorkstationInitialize::SelfBootstrap::WithLogger) if respond_to? 'logger'
37
- @workstation
33
+ # def get_workstation
34
+ # debug_worklog "Get workstation from #{self.class}"
35
+ # @workstation = ChefConfigResource.new if @workstation.nil?
36
+ # swap_workstation(ChefWorkstationInitialize::SelfBootstrap::WithLogger) if respond_to? 'logger'
37
+ # @workstation
38
+ # end
39
+
40
+ def workstation_resource
41
+ @workstation_data ||= (
42
+ if Chef::Config[:selfbootstrap].nil?
43
+ config_loader = ChefConfig::WorkstationConfigLoader.new(nil)
44
+ Chef::Config.from_file(config_loader.config_location) unless config_loader.config_location.nil?
45
+ default_workstation_data.deep_merge Chef::Config[:selfbootstrap]
46
+ end
47
+ )
48
+ @workstation_data
38
49
  end
39
50
  end
40
51
  end
@@ -9,20 +9,11 @@
9
9
  # camel-casing throughout the remainder of the name.
10
10
  #
11
11
 
12
- require 'withlogger'
12
+ require_relative 'nochef'
13
13
  require_relative 'withchef/selfbootstrap'
14
- require 'nochef'
15
14
 
16
15
  module ChefWorkstationInitialize
17
16
  module SelfBootstrap
18
- if respond_to? 'logger'
19
- include ChefWorkstationInitialize::SelfBootstrap::WithLogger
20
- elsif respond_to? 'Chef'
21
- include ChefWorkstationInitialize::SelfBootstrap::WithChef
22
- else
23
- include ChefWorkstationInitialize::SelfBootstrap::NoChef
24
- end
25
-
26
17
  module WithChef
27
18
  include ChefWorkstationInitialize::SelfBootstrap::WithChef::SelfBootstrapHelpers
28
19
  #
@@ -18,12 +18,14 @@
18
18
  # camel-casing throughout the remainder of the name.
19
19
  #
20
20
 
21
- require_relative 'nochef'
21
+ require_relative '../withchef'
22
22
 
23
23
  module ChefWorkstationInitialize
24
24
  module SelfBootstrap
25
25
  module WithLogger
26
- module DefaultValuesHelpers
26
+ module DefaultMethodsHelpers
27
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef::SelfBootstrapHelpers
28
+
27
29
  def worklog(logstr)
28
30
  logger.warn("\n\n(#{worklog_counter})WORKLOG:: #{logstr}\n\n")
29
31
  end
@@ -9,32 +9,32 @@
9
9
  # camel-casing throughout the remainder of the name.
10
10
  #
11
11
 
12
- require_relative 'defaultvalues'
12
+ require_relative 'defaultmethods'
13
13
 
14
14
  module ChefWorkstationInitialize
15
15
  module SelfBootstrap
16
16
  module WithLogger
17
17
  module WorkstationResourceHelpers
18
- include ChefWorkstationInitialize::SelfBootstrap::WithLogger::DefaultValuesHelpers
18
+ include ChefWorkstationInitialize::SelfBootstrap::WithLogger::DefaultMethodsHelpers
19
19
 
20
- class ChefLoggerResource < ChefWorkstationInitialize::SelfBootstrap::WithChef::WorkstationResourceHelpers::ChefConfigResource
21
- include ChefWorkstationInitialize::SelfBootstrap::WithLogger
20
+ # class ChefLoggerResource < ChefWorkstationInitialize::SelfBootstrap::WithChef::WorkstationResourceHelpers::ChefConfigResource
21
+ # include ChefWorkstationInitialize::SelfBootstrap::WithLogger
22
22
 
23
- def [](key)
24
- debug_worklog('Searching config key" ' + key.to_s + '"') unless key.to_s == 'debug'
25
- if default_workstation_resource.key?(key)
26
- default_workstation_resource[key]
27
- elsif default_workstation_resource.key?(key.to_s)
28
- default_workstation_resource[key.to_s]
29
- end
30
- end
31
- end
23
+ # def [](key)
24
+ # debug_worklog('Searching config key" ' + key.to_s + '"') unless key.to_s == 'debug'
25
+ # if default_workstation_resource.key?(key)
26
+ # default_workstation_resource[key]
27
+ # elsif default_workstation_resource.key?(key.to_s)
28
+ # default_workstation_resource[key.to_s]
29
+ # end
30
+ # end
31
+ # end
32
32
 
33
- def get_workstation
34
- debug_worklog "Get workstation from #{self.class}"
35
- @workstation = ChefLoggerResource.new if @workstation.nil?
36
- @workstation
37
- end
33
+ # def get_workstation
34
+ # debug_worklog "Get workstation from #{self.class}"
35
+ # @workstation = ChefLoggerResource.new if @workstation.nil?
36
+ # @workstation
37
+ # end
38
38
  end
39
39
  end
40
40
  end
@@ -9,17 +9,11 @@
9
9
  # camel-casing throughout the remainder of the name.
10
10
  #
11
11
 
12
- require 'withchef'
12
+ require_relative 'withchef'
13
13
  require_relative 'withlogger/selfbootstrap'
14
14
 
15
15
  module ChefWorkstationInitialize
16
16
  module SelfBootstrap
17
- if respond_to? 'logger'
18
- include ChefWorkstationInitialize::SelfBootstrap::WithLogger
19
- else
20
- include ChefWorkstationInitialize::SelfBootstrap::WithChef
21
- end
22
-
23
17
  module WithLogger
24
18
  include ChefWorkstationInitialize::SelfBootstrap::WithLogger::SelfBootstrapHelpers
25
19
  #
data/lib/selfbootstrap.rb CHANGED
@@ -13,9 +13,11 @@ require_relative 'selfbootstrap/withlogger'
13
13
 
14
14
  module ChefWorkstationInitialize
15
15
  module SelfBootstrap
16
+ include ChefWorkstationInitialize::SelfBootstrap::NoChef
17
+
16
18
  def self.bootstrap
17
- extend ChefWorkstationInitialize::SelfBootstrap::NoChef
18
- get_workstation.selfbootstrap
19
+ extend ChefWorkstationInitialize::SelfBootstrap
20
+ bootstrap_self
19
21
  end
20
22
 
21
23
  class ::Array
@@ -41,7 +43,11 @@ module ChefWorkstationInitialize
41
43
  v2
42
44
  end
43
45
  end
44
- merge(second, &merger)
46
+ if second.nil?
47
+ self
48
+ else
49
+ merge(second, &merger)
50
+ end
45
51
  end
46
52
 
47
53
  def stringify_keys!
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ puts $LOAD_PATH.unshift File.join(File.dirname(File.dirname(__dir__)), %w(lib))
4
+
5
+ ::Dir.chdir __dir__
6
+
7
+ require 'selfbootstrap'
8
+ ChefWorkstationInitialize::SelfBootstrap.bootstrap
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selfbootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Provencher
@@ -35,12 +35,40 @@ cert_chain:
35
35
  +V3ectLBpuoKM8f/ZFMnUPA0mAv5e7J6u9IBwyNj/cy+wLOAbpPdmhoKZXCpQcno
36
36
  ysBBJbi//0tgFWwC4vOaDMch
37
37
  -----END CERTIFICATE-----
38
- date: 2022-10-18 00:00:00.000000000 Z
39
- dependencies: []
38
+ date: 2022-10-21 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: chef
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "<="
45
+ - !ruby/object:Gem::Version
46
+ version: '17.10'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "<="
52
+ - !ruby/object:Gem::Version
53
+ version: '17.10'
54
+ - !ruby/object:Gem::Dependency
55
+ name: test-kitchen
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '4'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "<"
66
+ - !ruby/object:Gem::Version
67
+ version: '4'
40
68
  description: Using Chef cookbook style and force any script using it to switch to
41
69
  chef even if it is not install. It will install it tho ;)
42
70
  email:
43
- - maintainers@localhost.local
71
+ - jimbo_dragon@hotmail.com
44
72
  executables:
45
73
  - selfbootstrap
46
74
  extensions: []
@@ -58,7 +86,7 @@ files:
58
86
  - lib/selfbootstrap/nochef/chef.rb
59
87
  - lib/selfbootstrap/nochef/chefrepo.rb
60
88
  - lib/selfbootstrap/nochef/commandline.rb
61
- - lib/selfbootstrap/nochef/defaultvalues.rb
89
+ - lib/selfbootstrap/nochef/defaultmethods.rb
62
90
  - lib/selfbootstrap/nochef/defaultworkstationresource.rb
63
91
  - lib/selfbootstrap/nochef/git.rb
64
92
  - lib/selfbootstrap/nochef/kitchen.rb
@@ -77,23 +105,24 @@ files:
77
105
  - lib/selfbootstrap/withchef/chef.rb
78
106
  - lib/selfbootstrap/withchef/chefrepo.rb
79
107
  - lib/selfbootstrap/withchef/commandline.rb
80
- - lib/selfbootstrap/withchef/defaultvalues.rb
108
+ - lib/selfbootstrap/withchef/defaultmethods.rb
81
109
  - lib/selfbootstrap/withchef/git.rb
82
110
  - lib/selfbootstrap/withchef/selfbootstrap.rb
83
111
  - lib/selfbootstrap/withchef/users.rb
84
112
  - lib/selfbootstrap/withchef/workstation.rb
85
113
  - lib/selfbootstrap/withchef/workstationresource.rb
86
114
  - lib/selfbootstrap/withlogger.rb
87
- - lib/selfbootstrap/withlogger/defaultvalues.rb
115
+ - lib/selfbootstrap/withlogger/defaultmethods.rb
88
116
  - lib/selfbootstrap/withlogger/selfbootstrap.rb
89
117
  - lib/selfbootstrap/withlogger/workstationresource.rb
90
- homepage: https://localhost.local/selfbootstrap
118
+ - test/exemple/bootstrap.rb
119
+ homepage: https://github.com/JimboDragonGit/chef_selfbootstrap
91
120
  licenses:
92
121
  - MIT
93
122
  metadata:
94
- bug_tracker_uri: https://localhost.local/selfbootstrap/issues
95
- changelog_uri: https://localhost.local/selfbootstrap/releases
96
- homepage_uri: https://localhost.local/selfbootstrap
123
+ bug_tracker_uri: https://github.com/JimboDragonGit/chef_selfbootstrap/issues
124
+ changelog_uri: https://github.com/JimboDragonGit/chef_selfbootstrap/releases
125
+ homepage_uri: https://github.com/JimboDragonGit/chef_selfbootstrap
97
126
  post_install_message:
98
127
  rdoc_options:
99
128
  - "--charset=UTF-8"
metadata.gz.sig CHANGED
Binary file