hiera-template 1.0.3 → 1.1.0
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/lib/template.rb +54 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba9af3b56b0fd2b81b46cb4e08214125bfd985ed
|
4
|
+
data.tar.gz: bd55eb318d26f6fd05a0b57fad7024a89292ca52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98514fc593241f4225c9b4073ec51e99cb27bac21e8b8d5803b49e3a3f2cc5c531b3c974d6f449309865b4400c6c22e8c1b3f1557020db0c83341507badd0467
|
7
|
+
data.tar.gz: 10367edaf9817e96446ed847ff1e9fe92d5bc2127c7daebd4aed4997722acc02604397763e7d249fda6dea963fc52df5c04ea97df61880a1cdb7a805aff1329e
|
data/lib/template.rb
CHANGED
@@ -23,9 +23,12 @@ module Template
|
|
23
23
|
# Init some class vars
|
24
24
|
@new_template_path = files[1]
|
25
25
|
@profile_path = files[0]
|
26
|
-
# @hiera_data_path = Extras.get_hiera_data_path
|
27
26
|
@keys = Hash.new
|
28
|
-
|
27
|
+
@data_groups = Hash.new
|
28
|
+
@data_groups["unknown"] = current_group = []
|
29
|
+
@cwd = File.expand_path File.dirname(__FILE__)
|
30
|
+
|
31
|
+
|
29
32
|
# Kick back to stdout
|
30
33
|
debug("In init definition")
|
31
34
|
info("Creating new template for #{@profile_path}")
|
@@ -33,6 +36,7 @@ module Template
|
|
33
36
|
|
34
37
|
# Run it
|
35
38
|
parse()
|
39
|
+
debug(@data_groups)
|
36
40
|
write()
|
37
41
|
end
|
38
42
|
|
@@ -56,28 +60,59 @@ module Template
|
|
56
60
|
def parse
|
57
61
|
info("Parsing #{@profile_path}")
|
58
62
|
profile = File.open(@profile_path)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
63
|
+
|
64
|
+
# For each data grouop, parse the file
|
65
|
+
profile.each_line do |line|
|
66
|
+
catch :unknown_group do
|
67
|
+
# If the line matches the data group, init a new array for the keys in that data group
|
68
|
+
if line.match(/\#\[/)
|
69
|
+
debug("Data group found on line: #{line}")
|
70
|
+
data_group = line.split('[').last.delete(']').chomp
|
71
|
+
info("Creating data group: #{data_group}")
|
72
|
+
@data_groups[data_group] = @current_group = []
|
73
|
+
debug("Data groups now include: #{@data_groups}")
|
74
|
+
|
75
|
+
# For all other lines, parse it for keys
|
76
|
+
elsif line.match(/hiera\(/)
|
77
|
+
debug("Current data group being added to: #{@current_group}")
|
78
|
+
debug("Data item found: #{line}")
|
79
|
+
data = line.split("(").last.chomp
|
80
|
+
data.delete! (")")
|
81
|
+
data.delete! ("\"")
|
82
|
+
data.delete! ("'")
|
83
|
+
data.delete! (",")
|
84
|
+
|
85
|
+
@current_group << data
|
86
|
+
|
87
|
+
info("Adding #{data}")
|
88
|
+
debug("Adding #{data} to #{@current_group} hash")
|
89
|
+
end
|
71
90
|
end
|
72
91
|
end
|
73
92
|
end
|
74
93
|
|
75
94
|
def write
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
template
|
95
|
+
# Create dotdir if needed:
|
96
|
+
unless Dir.exists?("#{Dir.home}/.hiera-template")
|
97
|
+
Dir.mkdir(File.join(Dir.home, '.hiera-template'), 0755)
|
98
|
+
end
|
99
|
+
unless Dir.exists?("#{Dir.home}/.hiera-template/templates")
|
100
|
+
Dir.mkdir("#{Dir.home}/.hiera-template/templates", 0755)
|
101
|
+
end
|
102
|
+
|
103
|
+
temp_path = "#{Dir.home}/.hiera-template/templates"
|
104
|
+
profile_name = @profile_path.split("/").last.split(".").first
|
105
|
+
|
106
|
+
@data_groups.each do |k,v|
|
107
|
+
write_hash = Hash.new
|
108
|
+
v.each do |key|
|
109
|
+
write_hash[key] = nil
|
110
|
+
end
|
111
|
+
info("Writing keys to new template #{temp_path}/#{profile_name}-#{k}-template.yaml")
|
112
|
+
template = File.open("#{temp_path}/#{profile_name}-#{k}-template.yaml", "w")
|
113
|
+
template.write(write_hash.to_yaml)
|
114
|
+
template.close
|
115
|
+
end
|
81
116
|
end
|
82
117
|
|
83
118
|
def verify(path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera-template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Malnick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|