hiera-expander 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +37 -1
- data/lib/hiera/backend/expander.rb +6 -4
- 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: 12af63c0a60f3aa8937bcfc02fb28611f56775ad
|
4
|
+
data.tar.gz: b8d25c1a72a31222567927714bb93b6a498080fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbc337c7272eb423f2b4e10fd8fe021db4b61129d1d9ea78cf4e9fd0d57685488306621d01ff7ab5a44fb6f23e90e51112db34e8a32f4f032854ea53ab09b250
|
7
|
+
data.tar.gz: f0a66e28e60181d2a5dd546b6b092e40c8c00deaca54229e8e242c35c8dc80904ed15439f6036d349d1f0ac8720dd80582dbdcd496b2597af9ac1f9e4af4b921
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,43 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
To enable expander, simply add the following to your hiera.yaml:
|
22
|
+
```
|
23
|
+
:backends
|
24
|
+
- expander
|
25
|
+
```
|
26
|
+
|
27
|
+
Once enabled, it will autoamtically expand your hierarchy. Take, for example, the following hierarchy:
|
28
|
+
```
|
29
|
+
:hierarchy:
|
30
|
+
- '%{subdomain}/%{fqdn}'
|
31
|
+
- env/%{my_env}/%{my_type}/%{my_subtype}
|
32
|
+
- global/%{my_type}/%{my_subtype}
|
33
|
+
- os/%{operatingsystem}/%{operatingsystemmajrelease}
|
34
|
+
- common
|
35
|
+
```
|
36
|
+
|
37
|
+
With hiera-expander enabled, your hierarchy would be expanded to the following:
|
38
|
+
|
39
|
+
```
|
40
|
+
:hierarchy:
|
41
|
+
- '%{subdomain}/%{fqdn}'
|
42
|
+
- '%{subdomain}'
|
43
|
+
- env/%{my_env}/%{my_type}/%{my_subtype}
|
44
|
+
- env/%{my_env}/%{my_type}
|
45
|
+
- env/%{my_env}
|
46
|
+
- global/%{my_type}/%{my_subtype}
|
47
|
+
- global/%{my_type}
|
48
|
+
- os/%{operatingsystem}/%{operatingsystemmajrelease}
|
49
|
+
- os/%{operatingsystem}
|
50
|
+
- common
|
51
|
+
```
|
52
|
+
|
53
|
+
Note that some of the roots (env, global and os) aren't actually expanded as well. Expanding non-interpolated roots would give you multiple "common" sources that would apply to *all* nodes - so by default, sources with non-interpolated roots aren't expanded down to the root. Should you actually desire this howerver, you can enable it by adding the following to your hiera.yaml:
|
54
|
+
```
|
55
|
+
:expander:
|
56
|
+
:include_roots: true
|
57
|
+
```
|
22
58
|
|
23
59
|
## Contributing
|
24
60
|
|
@@ -20,7 +20,7 @@ require 'hiera' # loads backend and config
|
|
20
20
|
|
21
21
|
class Hiera
|
22
22
|
module Expander
|
23
|
-
VERSION = "0.1.
|
23
|
+
VERSION = "0.1.2"
|
24
24
|
|
25
25
|
def self.config
|
26
26
|
@config ||= {
|
@@ -57,6 +57,8 @@ class Hiera
|
|
57
57
|
|
58
58
|
# interpolate and expand sources
|
59
59
|
hierarchy.collect! do |source|
|
60
|
+
static_root = source.include?('/') && !source[/^([^\/]+)/,1].include?('%{')
|
61
|
+
|
60
62
|
case method(:parse_string).parameters.size
|
61
63
|
when 4 then
|
62
64
|
source = parse_string(source, scope, {}, :order_override => override)
|
@@ -70,7 +72,7 @@ class Hiera
|
|
70
72
|
# duplicate source detection and removal phase.
|
71
73
|
next if source.empty? || source =~ %r:(^/|//):
|
72
74
|
|
73
|
-
expand_source(source)
|
75
|
+
expand_source(source, !static_root)
|
74
76
|
end.flatten!.reject!(&:nil?)
|
75
77
|
|
76
78
|
# detect duplicate sources and removing them using a
|
@@ -101,7 +103,7 @@ class Hiera
|
|
101
103
|
#
|
102
104
|
# If you require the roots on all sources, simply set the config
|
103
105
|
# entry 'include_roots' to true.
|
104
|
-
def expand_source(source)
|
106
|
+
def expand_source(source, interpolated_root)
|
105
107
|
return [source] unless Expander.config[:expand_sources]
|
106
108
|
|
107
109
|
root, path = source.split('/', 2)
|
@@ -112,7 +114,7 @@ class Hiera
|
|
112
114
|
while subpath = path.pop
|
113
115
|
paths << File.join(root, *path, subpath)
|
114
116
|
end
|
115
|
-
paths << root if Expander.config[:include_roots]
|
117
|
+
paths << root if Expander.config[:include_roots] || interpolated_root
|
116
118
|
end
|
117
119
|
end
|
118
120
|
end
|