hiera-template 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/create_template.rb +4 -0
- data/lib/template.rb +106 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 293f82959504581ece4c86c221a6cfa203a84452
|
4
|
+
data.tar.gz: 03522481ac970ca949e0de96a2fb3beffe6c839a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc6b1af32e1517e711bcb19344beeb9fd248a0b8eb0e8033460988e5b08c21fa2ea146c2a8f1ad7aafb470068787df02a222a5e0e043b6d4afa0987b3bdb09ce
|
7
|
+
data.tar.gz: 4adc32f5c89424c8058be0ff30a781941c8c7d2bc17f866de7d7394b83fa442bfb2b29d153b5339cb60c932233b824b277a5f952168d4ad0a8dc5ad49c91e9b3
|
data/lib/template.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'logger'
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
$LOAD_PATH << '.'
|
6
|
+
|
7
|
+
module Template
|
8
|
+
class Create
|
9
|
+
#include Extras
|
10
|
+
def initialize(profile_path, new_template_path)
|
11
|
+
# Parse options
|
12
|
+
params,files = parseopts(ARGV)
|
13
|
+
|
14
|
+
# Log it
|
15
|
+
@log = Logger.new(STDOUT)
|
16
|
+
@log.level = params[:logger_level] || Logger::INFO
|
17
|
+
if params[:logger_level] == Logger::DEBUG
|
18
|
+
debug("Logger set to DEBUG")
|
19
|
+
else
|
20
|
+
info("Logger set to INFO")
|
21
|
+
end
|
22
|
+
|
23
|
+
# Init some class vars
|
24
|
+
@new_template_path = files[1]
|
25
|
+
@profile_path = files[0]
|
26
|
+
# @hiera_data_path = Extras.get_hiera_data_path
|
27
|
+
@keys = Hash.new
|
28
|
+
|
29
|
+
# Kick back to stdout
|
30
|
+
debug("In init definition")
|
31
|
+
info("Creating new template for #{@profile_path}")
|
32
|
+
info("New template path #{@new_template_path}")
|
33
|
+
|
34
|
+
# Run it
|
35
|
+
parse()
|
36
|
+
write()
|
37
|
+
end
|
38
|
+
|
39
|
+
def parseopts(argv)
|
40
|
+
params = {}
|
41
|
+
parser = OptionParser.new
|
42
|
+
|
43
|
+
parser.on("-D") {
|
44
|
+
params[:logger_level] = Logger::DEBUG
|
45
|
+
}
|
46
|
+
|
47
|
+
parser.on("-s") {
|
48
|
+
params[:squeeze_extra_newlines] = true
|
49
|
+
}
|
50
|
+
|
51
|
+
files = parser.parse(ARGV)
|
52
|
+
|
53
|
+
[params,files]
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse
|
57
|
+
info("Parsing #{@profile_path}")
|
58
|
+
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}")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
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
|
81
|
+
end
|
82
|
+
|
83
|
+
def verify(path)
|
84
|
+
unless path.absolute?
|
85
|
+
error("Path #{path} must be absolute")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def error(message)
|
90
|
+
@log.error(message)
|
91
|
+
abort
|
92
|
+
end
|
93
|
+
|
94
|
+
def debug(message)
|
95
|
+
@log.debug(message)
|
96
|
+
end
|
97
|
+
|
98
|
+
def warn(message)
|
99
|
+
@log.warn(message)
|
100
|
+
end
|
101
|
+
|
102
|
+
def info(message)
|
103
|
+
@log.info(message)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hiera-template
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Malnick
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- malnick@gmail.com
|
16
|
+
executables:
|
17
|
+
- create_template.rb
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/template.rb
|
22
|
+
- bin/create_template.rb
|
23
|
+
homepage:
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.0.14
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Create hiera templates
|
47
|
+
test_files: []
|
48
|
+
has_rdoc:
|