mofa 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 +4 -4
- data/.gitignore +2 -0
- data/lib/mofa/attributes_map.rb +41 -3
- data/lib/mofa/hostlist.rb +3 -2
- data/lib/mofa/mofa_cmd.rb +1 -0
- data/lib/mofa/mofa_yml.rb +0 -2
- data/lib/mofa/source_cookbook.rb +3 -3
- data/lib/mofa/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03031f673e7c4110dd86dd3844d81907b8f9b0de
|
4
|
+
data.tar.gz: 1eae6a2a9bb2aebb0989db8e2f23af1f55953d8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c13f374e59288c9e37ab0586d4ab548a4ab46732edf23960cfcbf0ae10ce39ff29448b8693e2a5107b04a82db5467d051d127508f594c909aadfa481e94787a2
|
7
|
+
data.tar.gz: 386230d9f5903c7c82fdfc1c19e593be0ddaf4e91d01a1f020c972f5d3a486eb23ce6af515b604239a42eaf774f45cbf8a390544c31b60f49ded68869c21b507
|
data/.gitignore
CHANGED
data/lib/mofa/attributes_map.rb
CHANGED
@@ -23,15 +23,53 @@ class AttributesMap
|
|
23
23
|
def generate
|
24
24
|
attr_all_roles = cookbook.mofa_yml.get_attr_for_role('all')
|
25
25
|
attr_all_roles_local = cookbook.mofa_yml_local.get_attr_for_role('all')
|
26
|
-
attr_all_roles
|
26
|
+
attr_all_roles = deep_merge(attr_all_roles, attr_all_roles_local)
|
27
|
+
|
27
28
|
hostlist.list.each do |hostname|
|
28
29
|
# Again: the underlying rule here is -> shortname = role
|
29
30
|
attr_host_role = cookbook.mofa_yml.get_attr_for_role(Hostlist::get_role(hostname))
|
30
31
|
attr_host_role_local = cookbook.mofa_yml_local.get_attr_for_role(Hostlist::get_role(hostname))
|
31
|
-
|
32
|
-
|
32
|
+
|
33
|
+
attr_host_role = deep_merge(attr_host_role, attr_host_role_local)
|
34
|
+
attr_per_host = deep_merge(attr_all_roles, attr_host_role)
|
35
|
+
|
36
|
+
attr_per_host = deep_parse(attr_per_host, '__SHORTNAME__', Hostlist::get_shortname(hostname))
|
37
|
+
|
33
38
|
@mp.store(hostname, attr_per_host)
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
42
|
+
def deep_parse(attr_hash, placeholder, content)
|
43
|
+
new_attr_hash = Marshal.load(Marshal.dump(attr_hash))
|
44
|
+
attr_hash.each do |key, value|
|
45
|
+
if value.is_a?(Hash)
|
46
|
+
new_attr_hash[key] = deep_parse(value, placeholder, content)
|
47
|
+
else
|
48
|
+
new_attr_hash[key] = value.gsub(Regexp.new(Regexp.escape(placeholder)), content)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
new_attr_hash
|
52
|
+
end
|
53
|
+
|
54
|
+
def deep_merge(attr_hash, attr_hash_local)
|
55
|
+
new_attr_hash = Marshal.load(Marshal.dump(attr_hash))
|
56
|
+
attr_hash.each do |key, value|
|
57
|
+
if attr_hash_local.key?(key)
|
58
|
+
if value.is_a?(Hash) && attr_hash_local[key].is_a?(Hash)
|
59
|
+
new_attr_hash[key] = deep_merge(value, attr_hash_local[key])
|
60
|
+
else
|
61
|
+
new_attr_hash[key] = attr_hash_local[key]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
# and now add all attributes that are in attr_hash_local but not in attr_hash
|
66
|
+
attr_hash_local.each do |key, value|
|
67
|
+
unless attr_hash.key?(key)
|
68
|
+
new_attr_hash.store(key, value)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
new_attr_hash
|
73
|
+
end
|
74
|
+
|
37
75
|
end
|
data/lib/mofa/hostlist.rb
CHANGED
@@ -40,7 +40,10 @@ class Hostlist
|
|
40
40
|
if File.exist?(json_file)
|
41
41
|
hosts_list_json = JSON.parse(File.read(json_file))
|
42
42
|
@list = hosts_list_json['data'].collect { |i| i['cname'] }
|
43
|
+
else
|
44
|
+
fail "Hostlist JSON-File not found: #{json_file}"
|
43
45
|
end
|
46
|
+
|
44
47
|
else
|
45
48
|
fail "Hostlist Service Url either has to be a http(s):// or a file:/// Url!"
|
46
49
|
end
|
@@ -61,8 +64,6 @@ class Hostlist
|
|
61
64
|
regex = Regexp.escape(regex).gsub(/__ASTERISK__/, '.*')
|
62
65
|
regex = '^' + regex + '$'
|
63
66
|
|
64
|
-
puts "regex=#{regex}"
|
65
|
-
|
66
67
|
@list.select! { |hostname| hostname.match(regex) }
|
67
68
|
end
|
68
69
|
|
data/lib/mofa/mofa_cmd.rb
CHANGED
@@ -55,6 +55,7 @@ class MofaCmd
|
|
55
55
|
|
56
56
|
def run_chef_solo_on_hosts
|
57
57
|
time = Time.new
|
58
|
+
puts
|
58
59
|
puts 'Chef-Solo Run started at ' + time.strftime('%Y-%m-%d %H:%M:%S')
|
59
60
|
puts "Will use ssh_user #{Mofa::Config.config['ssh_user']} and ssh_key_file #{Mofa::Config.config['ssh_keyfile']}"
|
60
61
|
at_least_one_chef_solo_run_failed = false
|
data/lib/mofa/mofa_yml.rb
CHANGED
@@ -33,8 +33,6 @@ class MofaYml
|
|
33
33
|
# for now only __ENV_COOKBOOK__ for cookbook name is supported
|
34
34
|
file_contents = File.read(path_to_mofayml)
|
35
35
|
file_contents.gsub!(/__ENV_COOKBOOK__/, @cookbook.name)
|
36
|
-
puts "FileContents: #{file_contents}"
|
37
36
|
@yml = YAML.load(file_contents)
|
38
|
-
puts "Parsed: #{@yml}"
|
39
37
|
end
|
40
38
|
end
|
data/lib/mofa/source_cookbook.rb
CHANGED
@@ -31,7 +31,7 @@ class SourceCookbook < Cookbook
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def cleanup
|
34
|
-
say "Removing folder #{pkg_dir}
|
34
|
+
say "Removing folder #{pkg_dir}... "
|
35
35
|
run "rm -r #{pkg_dir}"
|
36
36
|
ok
|
37
37
|
end
|
@@ -100,7 +100,7 @@ class SourceCookbook < Cookbook
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def berks_install_package
|
103
|
-
say "Running \"berks install\" and
|
103
|
+
say "Running \"berks install\" and \"berks package\" on Cookbook in #{source_dir}...#{nl}"
|
104
104
|
|
105
105
|
redirect_stdout = (Mofa::CLI::option_verbose) ? '' : '> /dev/null'
|
106
106
|
Bundler.with_clean_env do
|
@@ -115,7 +115,7 @@ class SourceCookbook < Cookbook
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def cleanup_and_repackage
|
118
|
-
say "Shrinking Cookbook Snapshot #{pkg_name}
|
118
|
+
say "Shrinking Cookbook Snapshot #{pkg_name}... "
|
119
119
|
|
120
120
|
tar_verbose = (Mofa::CLI::option_debug) ? 'v' : ''
|
121
121
|
|
data/lib/mofa/version.rb
CHANGED