hiera-template 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/template.rb +54 -19
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 306f24d5d884749ca90a11cf54dbb8e2c5fbbe30
4
- data.tar.gz: f6f3be67ede23520fb60ad214ce9a645c1997d71
3
+ metadata.gz: ba9af3b56b0fd2b81b46cb4e08214125bfd985ed
4
+ data.tar.gz: bd55eb318d26f6fd05a0b57fad7024a89292ca52
5
5
  SHA512:
6
- metadata.gz: b5b99dff21fa867c1b180efb8b1860eedbe4bcf7e24323a079083c0f4d159825b4dd32e0f6d760bb1ea6d66213861b4e01285fcf9a661c2c9569f8878f32e5bd
7
- data.tar.gz: f39f15a8fcf86793ffcb139d9f74ddd3ac4ba4c2fa767d48d05334aa3e0a6fe8178718e867ee3bf2db2352bd5cecfbc97036f442da7a977d919229ac9220808f
6
+ metadata.gz: 98514fc593241f4225c9b4073ec51e99cb27bac21e8b8d5803b49e3a3f2cc5c531b3c974d6f449309865b4400c6c22e8c1b3f1557020db0c83341507badd0467
7
+ data.tar.gz: 10367edaf9817e96446ed847ff1e9fe92d5bc2127c7daebd4aed4997722acc02604397763e7d249fda6dea963fc52df5c04ea97df61880a1cdb7a805aff1329e
@@ -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
- profile.each_line do |line|
60
- if line.match(/hiera\(/)
61
- debug("Data item found: #{line}")
62
- data = line.split("(").last.chomp
63
- debug("Data item split to: #{data}")
64
- data.delete! (")")
65
- data.delete! ("\"")
66
- data.delete! ("'")
67
- data.delete! (",")
68
- debug("Data item after deletes: #{data}")
69
- @keys[data] = nil
70
- info("Adding #{data}")
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
- info("Writing keys to new template #{@new_template_path}")
77
- template = File.open(@new_template_path, 'w')
78
- @keys.to_hash
79
- template.write(@keys.to_yaml)
80
- template.close
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.3
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-01 00:00:00.000000000 Z
11
+ date: 2014-11-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: