hieracles 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 979857ccc68e688d421a488ae1d7a46e43363208
4
- data.tar.gz: 6ddb11e2037df811f6c209d8def3f0fc25805427
3
+ metadata.gz: 4db8ec53dcd991137c7b1f4348de57cb175c7ced
4
+ data.tar.gz: 4a127e0e7c5b4f5e10aea37991cf82b9a48b888f
5
5
  SHA512:
6
- metadata.gz: d30867447a99006f2a4a3d70b027e54c25630b04aabf65ec41a53801846b2f2e347a3fcc9ddf73859e05b25475da7e18b1428049b1e9abaedab6da9fdf6b4d54
7
- data.tar.gz: d3556118c9d8230a9b472668a475c23c3a2ccd365365ed818cc86b94fca94b881091a1d52614c4e3466b1953739617d6a6d967667b2b859636e046b573b68a39
6
+ metadata.gz: cf8bfbe6606861d66931e0d3e065b1f3aff29eb25d7ec5dce8cbb6d5072e00de0c19bfac6f2f23b24dbd504f711461938ad2e3a375087af10fef54e0a58fba34
7
+ data.tar.gz: edd1d70376daac1a0a458da5348e271ea89257c4140db2b6fe83607e2f6199b23683590290cfd76246ad8aff34bfbcbea2146f0719ec1607139a8222e8d01223
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Hieracles Changelog
2
2
  =======================
3
3
 
4
+ ### 0.1.3 - 2015-11-12
5
+ - added scope (facts) interpretation for the hiera file
6
+ (very basic interpolation, not yet hiera-lib level)
7
+
4
8
  ### 0.1.2 - 2015-11-12
5
9
  - fix yaml more for case of nilclass in params
6
10
  - fix the case when a params file is empty
data/README.md CHANGED
@@ -48,6 +48,7 @@ Configuration variables are:
48
48
  - encpath
49
49
  - hierafile
50
50
  - format
51
+ - defaultscope
51
52
 
52
53
  For an example setup you can check in `spec/files`.
53
54
 
@@ -84,8 +85,8 @@ Usage
84
85
  -j <fact_file> - facts in json format
85
86
 
86
87
 
87
- About facts
88
- ------------------
88
+ About facts aka. scope
89
+ ------------------------
89
90
 
90
91
  _(work in progress)_
91
92
 
@@ -95,6 +96,24 @@ Like with Hiera CLI you can use hieracles with defined top-scope variables. Thos
95
96
  - `-y <fact_file>` which takes the fact file from a yaml source created by `facter -y` on your node for example, but it can be written manually for experimentation purposes.
96
97
  - `-j <fact_file>` same as above, but with output of `facter -j`
97
98
 
99
+ You can define a default scope in your configuration file `defaultscope` in `~/.confg/hieracles/config.yml`. For example:
100
+
101
+ ---
102
+ colors: true
103
+ classpath: farm_modules/%s/manifests/init.pp
104
+ hierafile: dev/hiera-local.yaml
105
+ encpath: enc
106
+ defaultscope:
107
+ operatingsystem: Debian
108
+ lsbdistcodename: Jessie
109
+
110
+ In order the scope with be built from:
111
+
112
+ - the config file
113
+ - if `-y <file>` option (or `-j`) is present the `defaultscope` in the config file will be totally ignored
114
+ - the `-p key=value` option with overide variable per variable
115
+
116
+
98
117
  Completion
99
118
  -------------
100
119
  There is a simple zsh completion file in `tools/completion`.
@@ -128,9 +147,9 @@ and install
128
147
 
129
148
  Todo
130
149
  --------------
131
- - add json format
132
- - add override information in yaml format
133
- - add a command to search for node according to a filter
150
+ - add json format (done)
151
+ - add override information in yaml format (done)
152
+ - add a command to search for node according to a filter (done)
134
153
  - add a command to find all nodes that use a given module
135
154
  - add a command that finds all nodes for which a params is defined
136
155
  - detect unused params
@@ -1,13 +1,15 @@
1
1
  require 'fileutils'
2
2
  require 'json'
3
3
  require 'yaml'
4
+ require 'hieracles/utils'
4
5
 
5
6
  module Hieracles
6
7
  # configuration singleton
7
8
  module Config
9
+ include Hieracles::Utils
8
10
  extend self
9
11
 
10
- attr_reader :extraparams, :server, :classpath, :facts,
12
+ attr_reader :extraparams, :server, :classpath, :scope,
11
13
  :modulepath, :hierafile, :basepath, :encpath, :format
12
14
 
13
15
  def load(options)
@@ -24,7 +26,7 @@ module Hieracles
24
26
  @format = (options[:format] || values['format'] || 'console').capitalize
25
27
  facts_file = options[:yaml_facts] || options[:json_facts]
26
28
  facts_format = options[:json_facts] ? :json : :yaml
27
- @facts = (facts_file && load_facts(facts_file, facts_format)) || {}
29
+ @scope = sym_keys((facts_file && load_facts(facts_file, facts_format)) || values['defaultscope'] || {})
28
30
  end
29
31
 
30
32
  def initconfig(file)
@@ -29,6 +29,8 @@ module Hieracles
29
29
  -h <hierafile>
30
30
  -b <basepath> default ./
31
31
  -e <encdir>
32
+ -y <fact_file> - facts in yaml format
33
+ -j <fact_file> - facts in json format
32
34
  -v just displays the version of Hieracles
33
35
  END
34
36
  end
@@ -1,5 +1,4 @@
1
1
  module Hieracles
2
-
3
2
  class Hiera
4
3
 
5
4
  def initialize
@@ -13,6 +13,7 @@ module Hieracles
13
13
  @hiera = Hieracles::Hiera.new
14
14
  @hiera_params = { fqdn: fqdn }.
15
15
  merge(get_hiera_params(fqdn)).
16
+ merge(Config.scope).
16
17
  merge(Config.extraparams)
17
18
  @fqdn = fqdn
18
19
  end
@@ -51,6 +52,7 @@ module Hieracles
51
52
  s = to_shallow_hash(data)
52
53
  s.each do |k,v|
53
54
  params[k] ||= []
55
+ # f needs interpolation
54
56
  params[k] << { value: v, file: f}
55
57
  end
56
58
  end
@@ -62,7 +64,10 @@ module Hieracles
62
64
  params = {}
63
65
  paths(without_common).each do |f|
64
66
  data = YAML.load_file(f)
65
- deep_merge!(params, data) if data
67
+ if data
68
+ # data needs interpolation
69
+ deep_merge!(params, data)
70
+ end
66
71
  end
67
72
  deep_sort(params)
68
73
  end
@@ -61,7 +61,7 @@ describe Hieracles::Config do
61
61
  it { expect(Hieracles::Config.extract_params(str)).to eq expected }
62
62
  end
63
63
 
64
- describe '.facts' do
64
+ describe '.scope' do
65
65
  context 'with a yaml file' do
66
66
  let(:options) do
67
67
  {
@@ -73,7 +73,7 @@ describe Hieracles::Config do
73
73
  let(:expected) { 'Debian' }
74
74
  before { Hieracles::Config.load options }
75
75
 
76
- it { expect(Hieracles::Config.facts['osfamily']).to eq expected }
76
+ it { expect(Hieracles::Config.scope[:osfamily]).to eq expected }
77
77
  end
78
78
  context 'with a json file' do
79
79
  let(:options) do
@@ -86,7 +86,7 @@ describe Hieracles::Config do
86
86
  let(:expected) { 'Debian' }
87
87
  before { Hieracles::Config.load options }
88
88
 
89
- it { expect(Hieracles::Config.facts['osfamily']).to eq expected }
89
+ it { expect(Hieracles::Config.scope[:osfamily]).to eq expected }
90
90
  end
91
91
  end
92
92
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hieracles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-11 00:00:00.000000000 Z
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler