hiera-multiyaml 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/hiera/backend/multiyaml_backend.rb +74 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eac3223c234dd53575b9ae011b64628cd941350e
|
4
|
+
data.tar.gz: e8e19159beff304e13b62e72090ef966ad9565c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7396be03c5408edffa71e5824d44bde3a612d6b04cb001bff0e2172611d522e3c1af09d058283736311cf675a80532fc72a40e955ae3e58fd3dfcaa365a2dd0
|
7
|
+
data.tar.gz: e07c6c1d2e438bbee050d538198ecc8a4c9e5d6645516dfaa4b30efd97aff0325bc60f678a26906fd3bd843808bdccb1e6631adf4c5584b6078ca6661fd87efd
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class Hiera
|
2
|
+
module Backend
|
3
|
+
class Multiyaml_backend
|
4
|
+
# XXX: There is no option to override the datadir/datafile function logic
|
5
|
+
# in Hiera::Backend, so there is a lot of copy paste code from
|
6
|
+
# Hiera::Backend and Hiera::Backend::Yaml_backend instead of inheritance
|
7
|
+
# or just calling it from here. The Hiera architecture sucks big dongs. :-(
|
8
|
+
|
9
|
+
def initialize(cache=nil)
|
10
|
+
require 'yaml'
|
11
|
+
Hiera.debug("Hiera MultiYAML-derp backend starting")
|
12
|
+
|
13
|
+
@cache = cache || Filecache.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def lookup(key, scope, order_override, resolution_type)
|
17
|
+
Hiera.debug("MultiYAML: Entering lookup method in MultiYAML backend!")
|
18
|
+
answer = nil
|
19
|
+
|
20
|
+
Config[:multiyaml][:backends].each do |backend|
|
21
|
+
backend = backend.to_sym
|
22
|
+
|
23
|
+
Hiera.debug("MultiYAML: Starting with backend #{backend}")
|
24
|
+
#Backend.datasourcefiles(:yaml, scope, "yaml", order_override) do |source, yamlfile|
|
25
|
+
Backend.datasources(scope, order_override) do |source|
|
26
|
+
Hiera.debug("MultiYAML: Looking for data source #{source} in MultiYAML #{backend}")
|
27
|
+
yamlfile = Backend.parse_answer(File.join(Config[backend][:datadir], "#{source}.yaml"), scope)
|
28
|
+
Hiera.debug("MultiYAML: Overriding yamlfile variable with #{yamlfile}")
|
29
|
+
|
30
|
+
if not File.exist?(yamlfile)
|
31
|
+
Hiera.debug("MultiYAML: Cannot find datafile #{yamlfile}, skipping")
|
32
|
+
next
|
33
|
+
end
|
34
|
+
|
35
|
+
Hiera.debug("MultiYAML: Found datafile #{yamlfile}, hooray!")
|
36
|
+
data = @cache.read_file(yamlfile, Hash) do |data|
|
37
|
+
YAML.load(data) || {}
|
38
|
+
end
|
39
|
+
|
40
|
+
next if data.empty?
|
41
|
+
next unless data.include?(key)
|
42
|
+
|
43
|
+
Hiera.debug("MultiYAML: Found #{key} in #{backend}/#{source}")
|
44
|
+
|
45
|
+
new_answer = Backend.parse_answer(data[key], scope)
|
46
|
+
answer = merge_answer(resolution_type, new_answer, answer)
|
47
|
+
end
|
48
|
+
Hiera.debug("MultiYAML: Done with backend #{backend}")
|
49
|
+
end
|
50
|
+
|
51
|
+
Hiera.debug("MultiYAML: Leaving lookup method in MultiYAML backend! Answer is #{answer}")
|
52
|
+
return answer
|
53
|
+
end
|
54
|
+
|
55
|
+
def merge_answer(resolution_type, new_answer, answer)
|
56
|
+
if not new_answer.nil?
|
57
|
+
case resolution_type
|
58
|
+
when :array
|
59
|
+
raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
|
60
|
+
answer ||= []
|
61
|
+
answer << new_answer
|
62
|
+
when :hash
|
63
|
+
raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
|
64
|
+
answer ||= {}
|
65
|
+
answer = Hiera::Backend.merge_answer(new_answer,answer)
|
66
|
+
else
|
67
|
+
answer = new_answer
|
68
|
+
end
|
69
|
+
end
|
70
|
+
return answer
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hiera-multiyaml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- denise stockman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Multiple yaml backend for Puppet
|
14
|
+
email: denise@stockmans.org
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/hiera/backend/multiyaml_backend.rb
|
20
|
+
homepage: http://rubygems.org/gems/hiera-multiyaml
|
21
|
+
licenses:
|
22
|
+
- Apache 2.0
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.0.14
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Multiple yaml backend for Puppet
|
44
|
+
test_files: []
|