mofa 0.5.11 → 0.5.12

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: 53a589ffb32931662ca28a41fbd8081a4471db52287d6b792a1033b64221803e
4
- data.tar.gz: 50920386da52fabe51ce55bf1dd4144ad49d9f7d26679d9d592da3ca1e9dca36
3
+ metadata.gz: 2c1eb88f1c036d2fde056ffc49cedba0bd79e952abd9bd66373fa8df0729f5a1
4
+ data.tar.gz: b0482279a20d8a1988f4e82bb2132cb62f071e7d06265cb9bf75a1b994a1bcd4
5
5
  SHA512:
6
- metadata.gz: d0aea4b5658276cfdae1bd83f72bbc705ea80b43bc87a15168d08f553912d1629c2a533bfb99895ef6d917420b728c5dfefa6ce391a7882627c5d0c373f7cd3d
7
- data.tar.gz: ed15e04c4eabebfc08c66e303bb112f8757543ea3c5ec8c3cd5f9184a9b5715d6a1607205a8a5b172462b967da9be51b0b4211f71a52709ce8ec5ff4c650f225
6
+ metadata.gz: a8960aae289ce4d22fdbcc0b5f6804a61e3b34a21e674176791c8d1ab2d013701f6ac1359b6ed64a58231319a5820c49f2141e80fcea6063a38d72ca9a598a55
7
+ data.tar.gz: a1280c2d557f7c7a53ebd1cfc5ccb00820b82320c58ab326380ab73ec6ae6cb2d55adf24d87160d66b60fd444648ae6d68ce530b6bb06bfb516698cd905da29f
data/.rubocop.yml CHANGED
@@ -1,9 +1,15 @@
1
+ Metrics/ParameterLists:
2
+ Enabled: false
3
+
1
4
  Metrics/LineLength:
2
5
  Enabled: false
3
6
 
4
7
  Metrics/MethodLength:
5
8
  Enabled: false
6
9
 
10
+ Metrics/BlockLength:
11
+ Enabled: false
12
+
7
13
  Metrics/ClassLength:
8
14
  Enabled: false
9
15
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.6.6
1
+ 2.6.5
data/Dockerfile ADDED
@@ -0,0 +1,12 @@
1
+ FROM docker.io/chef/chefdk:1.6.11
2
+
3
+ RUN apt update && apt upgrade --yes && \
4
+ apt install build-essential rsync --yes && \
5
+ gem install mofa
6
+
7
+ RUN mkdir /root/.mofa
8
+
9
+ COPY config.docker.yml /root/.mofa/config.yml
10
+
11
+ ENV PATH="/root/.chefdk/gem/ruby/2.3.0/bin:${PATH}"
12
+
data/README.md CHANGED
@@ -52,7 +52,7 @@ Before you can start using mofa please create a config file:
52
52
 
53
53
  # local Development
54
54
 
55
- $ git clone https://github.com/hybris/mofa.git
55
+ $ git clone https://github.com/pingworks/mofa.git
56
56
  $ cd mofa
57
57
  $ bundle install
58
58
  $ cd ../somewhere_chef-env_some_cookbook
data/config.docker.yml ADDED
@@ -0,0 +1,39 @@
1
+ # global mofa settings
2
+
3
+ # Admin User Account that should be used for all mofa tasks.
4
+ # The user has to be able to login passwordless
5
+ # and has tohave passwordless sudo permissions.
6
+ ssh_user: sccchef
7
+ ssh_keyfile: ~/.ssh/id_rsa_sccchef
8
+
9
+ # where to build tmporary cookbook packages and so on
10
+ tmp_dir: /var/tmp
11
+
12
+ # A REST-Webservice that returns a list of hosts that are potentially
13
+ # manageable with this mofa.
14
+ service_hostlist_url: file:///opt/workshopbox/etc/hostlist.json
15
+ service_hostlist_default_filter: "localhost"
16
+ #service_hostlist_api_key: xyz
17
+
18
+ # The cookbook architectural pattern should becodified by following
19
+ # a coonaming schema:
20
+ # * Cookbooks beginning with "env_*" are Envrionment Cookbooks
21
+ # * Cookbooks haven a prefix like "<organisation_name>_*" are
22
+ # so-called Wrapper Cookbooks
23
+ # * Cookbooks having a "base_" Prefix are Base Cookbooks
24
+
25
+ cookbook_type_indicator:
26
+ env: "^env_.*"
27
+ wrapper: "^(scc_|fos_|allcop_).*"
28
+ base: ".*_base$"
29
+
30
+ # Binrepo for released cookbooks
31
+ binrepo_base_url: 'https://berks-api/cookbooks'
32
+
33
+ # Releasing into binrepo
34
+ binrepo_host: berks-api
35
+ binrepo_ssh_user: berks
36
+ binrepo_ssh_port: 22
37
+ binrepo_ssh_keyfile: /id_rsa
38
+ binrepo_import_dir: /data/cookbooks/import
39
+
data/lib/mofa/cli.rb CHANGED
@@ -16,14 +16,17 @@ module Mofa
16
16
  class_option :debug, :type => :boolean, :aliases => '-vv', :desc => 'be very vebose'
17
17
 
18
18
  desc 'provision <cookbook>', 'provisions Targethost(s) using a given cookbook.'
19
- method_option :ignore_ping, :type => :boolean, :aliases => '-p'
19
+ method_option :ignore_ping, :type => :boolean, :aliases => '-P'
20
20
  method_option :target, :type => :string, :aliases => '-t'
21
21
  method_option :concrete_target, :type => :string, :aliases => '-T'
22
- method_option :sshport, :type => :string, :aliases => '-P'
23
22
  method_option :runlist, :type => :string, :aliases => '-o'
24
23
  method_option :attributes, :type => :string, :aliases => '-j'
25
24
  method_option :service_hostlist_url, :type => :string
26
25
  method_option :override_mofa_secrets, :type => :string, :aliases => '-S'
26
+ method_option :ssh_port, :type => :string, :aliases => '-p', :default => '22'
27
+ method_option :ssh_user, :type => :string, :aliases => '-u', :default => 'sccchef'
28
+ method_option :ssh_keyfile, :type => :string, :aliases => '-i', :default => '~/.ssh/id_rsa_sccchef'
29
+ method_option :tmp_dir, :type => :string, :aliases => '-w', :default => '~/tmp/mofa'
27
30
 
28
31
  def provision(cookbook_name_or_path)
29
32
  set_verbosity
@@ -31,7 +34,6 @@ module Mofa
31
34
  cookbook_name_or_path ||= '.'
32
35
 
33
36
  target_filter = options[:target]
34
- #target_filter ||= Mofa::Config.config['profiles']['default']['target']
35
37
 
36
38
  token = MofaCmd.generate_token
37
39
 
@@ -48,13 +50,13 @@ module Mofa
48
50
  cmd.options = options
49
51
 
50
52
  cmd.prepare
51
- cmd.execute(options[:sshport])
53
+ cmd.execute(options[:ssh_port], options[:ssh_user], options[:ssh_keyfile])
52
54
  cmd.cleanup
53
55
  end
54
56
 
55
57
  desc 'upload <cookbook>', 'package & upload cookbook into binrepo'
56
58
  method_option :binrepo_host, :type => :string
57
- method_option :binrepo_sshport, :type => :string
59
+ method_option :binrepo_ssh_port, :type => :string
58
60
  method_option :binrepo_ssh_user, :type => :string
59
61
  method_option :binrepo_ssh_keyfile, :type => :string
60
62
 
@@ -80,29 +82,6 @@ module Mofa
80
82
  puts VERSION
81
83
  end
82
84
 
83
- desc 'config', 'prints out mofa config.'
84
-
85
- def config
86
- config_print
87
- end
88
-
89
- desc 'setup', 'setup initial configuration'
90
-
91
- def setup
92
- set_verbosity
93
-
94
- case
95
- when !File.exists?("#{ENV['HOME']}/.mofa/config.yml")
96
- begin
97
- config_create
98
- end until config_valid?
99
- else
100
- begin
101
- config_edit
102
- end until config_valid?
103
- end
104
- end
105
-
106
85
  def self.option_verbose
107
86
  @@option_verbose
108
87
  end
@@ -131,33 +110,6 @@ module Mofa
131
110
  say detail, :red
132
111
  end
133
112
 
134
- def config_create
135
- say 'Creating a new mofa config (~/.mofa/config.yml)...'
136
-
137
- say '- not implemented yet -'
138
-
139
- end
140
-
141
- def config_edit
142
- say 'Editing mofa config (~/.mofa/config.yml)...'
143
-
144
- say '- not implemented yet -'
145
-
146
- end
147
-
148
- def config_print
149
- say 'Mofa Config (~/.mofa/config.yml):'
150
-
151
- say '- not implemented yet -'
152
-
153
- end
154
-
155
- def config_valid?
156
- say 'Validating Mofa config (~/.mofa/config.yml)...'
157
- say '- not implemented yet -'
158
- true
159
- end
160
-
161
113
  def self.exit_on_failure?
162
114
  true
163
115
  end
@@ -14,7 +14,7 @@ class ProvisionCmd < MofaCmd
14
14
  cookbook.prepare
15
15
  end
16
16
 
17
- def execute(ssh_port = 22)
17
+ def execute(ssh_port, ssh_user, ssh_keyfile)
18
18
  cookbook.execute
19
19
 
20
20
  hostlist.retrieve
@@ -30,7 +30,7 @@ class ProvisionCmd < MofaCmd
30
30
 
31
31
  puts "Hostlist after runlist filtering: #{hostlist.list.inspect}"
32
32
 
33
- exit_code = run_chef_solo_on_hosts(ssh_port)
33
+ exit_code = run_chef_solo_on_hosts(ssh_port, ssh_user, ssh_keyfile)
34
34
 
35
35
  exit_code
36
36
  end
@@ -56,12 +56,12 @@ class ProvisionCmd < MofaCmd
56
56
  host_available
57
57
  end
58
58
 
59
- def prepare_host(hostname, host_index, solo_dir, ssh_port = Mofa::Config.config['ssh_port'] )
59
+ def prepare_host(hostname, host_index, solo_dir, ssh_port, ssh_user, ssh_keyfile)
60
60
  puts
61
61
  puts '----------------------------------------------------------------------'
62
62
  puts "Chef-Solo on Host #{hostname} (#{host_index}/#{hostlist.list.length})"
63
63
  puts '----------------------------------------------------------------------'
64
- Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
64
+ Net::SSH.start(hostname, ssh_user, keys: [ssh_keyfile], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
65
65
  puts "Remotely creating solo_dir \"#{solo_dir}\" on host #{hostname}"
66
66
  # remotely create the temp folder
67
67
  out = ssh_exec!(ssh, "[ -d #{solo_dir} ] || mkdir #{solo_dir}")
@@ -90,8 +90,6 @@ class ProvisionCmd < MofaCmd
90
90
  file.write(solo_rb)
91
91
  end
92
92
  end
93
- # log_level :info
94
- # log_location "#{solo_dir}/log"
95
93
 
96
94
  def create_node_json(sftp, hostname, solo_dir, attributes_map)
97
95
  puts "Remotely creating \"#{solo_dir}/node.json\" on #{hostname}..."
@@ -121,13 +119,13 @@ class ProvisionCmd < MofaCmd
121
119
  end
122
120
  end
123
121
 
124
- def run_chef_solo_on_hosts(ssh_port = Mofa::Config.config['ssh_port'])
122
+ def run_chef_solo_on_hosts(ssh_port, ssh_user, ssh_keyfile)
125
123
  time = Time.new
126
124
  # Create a temp working dir on the target host
127
125
  solo_dir = '/var/tmp/' + time.strftime('%Y-%m-%d_%H%M%S')
128
126
  puts
129
127
  puts 'Chef-Solo Run started at ' + time.strftime('%Y-%m-%d %H:%M:%S')
130
- puts "Will use ssh_user #{Mofa::Config.config['ssh_user']}, ssh_port #{ssh_port} and ssh_key_file #{Mofa::Config.config['ssh_keyfile']}"
128
+ puts "Will use ssh_user '#{ssh_user}', ssh_port '#{ssh_port}' and ssh_keyfile '#{ssh_keyfile}'"
131
129
  at_least_one_chef_solo_run_failed = false
132
130
  chef_solo_runs = {}
133
131
  host_index = 0
@@ -144,9 +142,9 @@ class ProvisionCmd < MofaCmd
144
142
  end
145
143
  end
146
144
 
147
- prepare_host(hostname, host_index, solo_dir, ssh_port)
145
+ prepare_host(hostname, host_index, solo_dir, ssh_port, ssh_user, ssh_keyfile)
148
146
 
149
- Net::SFTP.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: ssh_port, use_agent: false, verbose: :error) do |sftp|
147
+ Net::SFTP.start(hostname, ssh_user, keys: [ssh_keyfile], port: ssh_port, use_agent: false, verbose: :error) do |sftp|
150
148
  # remotely creating solo.rb
151
149
  create_solo_rb(sftp, hostname, solo_dir)
152
150
 
@@ -164,7 +162,7 @@ class ProvisionCmd < MofaCmd
164
162
  # Do it -> Execute the chef-solo run!
165
163
  begin
166
164
  begin
167
- Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
165
+ Net::SSH.start(hostname, ssh_user, keys: [ssh_keyfile], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
168
166
  puts "Remotely unpacking Cookbook Package #{cookbook.pkg_name}... "
169
167
  ssh.exec!("cd #{solo_dir}; tar xvfz #{cookbook.pkg_name}") do |_ch, _stream, line|
170
168
  puts line if Mofa::CLI.option_debug
@@ -181,7 +179,7 @@ class ProvisionCmd < MofaCmd
181
179
  raise e
182
180
  end
183
181
  begin
184
- Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
182
+ Net::SSH.start(hostname, ssh_user, keys: [ssh_keyfile], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
185
183
  puts "Remotely running chef-solo -c #{solo_dir}/solo.rb -j #{solo_dir}/node.json"
186
184
  chef_run_exit_code = 0
187
185
  ssh.exec!("sudo chef-solo -c #{solo_dir}/solo.rb -j #{solo_dir}/node.json") do |_ch, _stream, line|
@@ -207,7 +205,7 @@ class ProvisionCmd < MofaCmd
207
205
  log_file.write('chef-solo run: FAIL')
208
206
  puts "ERRORS detected while provisioning #{hostname} (#{e.message})."
209
207
  end
210
- Net::SSH.start(hostname, Mofa::Config.config['ssh_user'], keys: [Mofa::Config.config['ssh_keyfile']], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
208
+ Net::SSH.start(hostname, ssh_user, keys: [ssh_keyfile], port: ssh_port, use_agent: false, verbose: :error) do |ssh|
211
209
  snapshot_or_release = cookbook.is_a?(SourceCookbook) ? 'snapshot' : 'release'
212
210
  out = ssh_exec!(ssh, "sudo chown -R #{Mofa::Config.config['ssh_user']}.#{Mofa::Config.config['ssh_user']} #{solo_dir}")
213
211
  puts "ERROR (#{out[0]}): #{out[2]}" if out[0] != 0
@@ -26,7 +26,7 @@ class ReleasedCookbook < Cookbook
26
26
 
27
27
  def prepare
28
28
  @pkg_name ||= "#{name}_#{version}-full.tar.gz"
29
- @pkg_dir = "#{Mofa::Config.config['tmp_dir']}/.mofa/#{token}"
29
+ @pkg_dir = "#{Mofa::CLI::option_tmp_dir}/.mofa/#{token}"
30
30
  set_cookbooks_url
31
31
  end
32
32
 
@@ -114,11 +114,11 @@ class ReleasedCookbook < Cookbook
114
114
  end
115
115
 
116
116
  def cleanup!
117
- unless (Dir.entries("#{Mofa::Config.config['tmp_dir']}/.mofa") - %w{ . .. }).empty?
118
- say "Removing content of folder #{Mofa::Config.config['tmp_dir']}/.mofa"
119
- run "rm -r #{Mofa::Config.config['tmp_dir']}/.mofa/*"
117
+ unless (Dir.entries("#{Mofa::CLI::option_tmp_dir}/.mofa") - %w{ . .. }).empty?
118
+ say "Removing content of folder #{Mofa::CLI::option_tmp_dir}/.mofa"
119
+ run "rm -r #{Mofa::CLI::option_tmp_dir}/.mofa/*"
120
120
  else
121
- say "Folder #{Mofa::Config.config['tmp_dir']}/.mofa is (already) clean."
121
+ say "Folder #{Mofa::CLI::option_tmp_dir}/.mofa is (already) clean."
122
122
  end
123
123
  end
124
124
 
@@ -77,11 +77,11 @@ class SourceCookbook < Cookbook
77
77
  end
78
78
 
79
79
  def cleanup!
80
- unless (Dir.entries("#{Mofa::Config.config['tmp_dir']}/.mofa") - %w{ . .. }).empty?
81
- say "Removing content of folder #{Mofa::Config.config['tmp_dir']}/.mofa"
82
- run "rm -r #{Mofa::Config.config['tmp_dir']}/.mofa/*"
80
+ unless (Dir.entries("#{Mofa::CLI::option_tmp_dir}/.mofa") - %w{ . .. }).empty?
81
+ say "Removing content of folder #{Mofa::CLI::option_tmp_dir}/.mofa"
82
+ run "rm -r #{Mofa::CLI::option_tmp_dir}/.mofa/*"
83
83
  else
84
- say "Folder #{Mofa::Config.config['tmp_dir']}/.mofa is (already) clean."
84
+ say "Folder #{Mofa::CLI::option_tmp_dir}/.mofa is (already) clean."
85
85
  end
86
86
  end
87
87
 
data/lib/mofa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mofa
2
- VERSION = '0.5.11'
2
+ VERSION = '0.5.12'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.11
4
+ version: 0.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Birk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-27 00:00:00.000000000 Z
11
+ date: 2021-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -204,12 +204,14 @@ files:
204
204
  - ".rubocop.yml"
205
205
  - ".ruby-version"
206
206
  - ".travis.yml"
207
+ - Dockerfile
207
208
  - Gemfile
208
209
  - Guardfile
209
210
  - LICENSE
210
211
  - README.md
211
212
  - Rakefile
212
213
  - bin/mofa
214
+ - config.docker.yml
213
215
  - config.yml.erb
214
216
  - lib/mofa.rb
215
217
  - lib/mofa/attributes_map.rb