hiera-mysql-json-backend-jruby 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +108 -47
- data/hiera-mysql-json-backend-puppetserver.gemspec +1 -1
- data/hiera-mysql-json-backend.gemspec +1 -1
- data/lib/hiera/backend/mysql_json_backend.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 022754036cab6f330dad8e5147e2b514c3e92b2b
|
4
|
+
data.tar.gz: a8ad4a2cdf2b31800e64555a0a70506062f2ddb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ded7f5e128f280f194f2daf8a8ddc8ed7a99aa32ca90539fd89ceaa88a8e906a68f7451f88150542cc41a6116a7d09de8aabee7eb700dcb2ea1f4f177f3980aa
|
7
|
+
data.tar.gz: 75230f6daeecc58948453df6946b888ccdc3399fb9c0376836d2a306163f24a68aa6af5b46bec77c178dc50674f314203e5d3cad5a3e3fe707bfeba917a2cf10
|
data/README.md
CHANGED
@@ -1,90 +1,151 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/hiera-mysql-json-backend.png)](http://badge.fury.io/rb/hiera-mysql-json-backend)
|
2
2
|
|
3
|
-
## hiera-mysql-backend
|
3
|
+
## hiera-mysql-json-backend
|
4
4
|
|
5
|
-
Alternate MySQL backend for Hiera
|
5
|
+
Alternate MySQL backend for Hiera with json support
|
6
6
|
|
7
|
-
This is a
|
7
|
+
This is a backend for Hiera based on
|
8
|
+
[hiera-mysql-backend](https://github.com/Telmo/hiera-mysql-backend).
|
8
9
|
|
9
|
-
### What
|
10
|
+
### What makes this backend different from the other mysql backends
|
10
11
|
|
11
|
-
|
12
|
+
This backend differs from
|
13
|
+
[hiera-mysql](https://github.com/crayfishx/hiera-mysql) and
|
14
|
+
[hiera-mysql-backend](https://github.com/Telmo/hiera-mysql-backend) in that it
|
15
|
+
expects queries to return json. This json is then parsed and the resulting data
|
16
|
+
structure is given back to the lookup.
|
12
17
|
|
13
|
-
|
18
|
+
### Usage
|
14
19
|
|
15
|
-
|
20
|
+
Puppet client:
|
16
21
|
|
17
|
-
|
22
|
+
`/opt/puppetlabs/puppet/bin/gem install hiera-mysql-json-backend mysql2`
|
18
23
|
|
19
|
-
|
24
|
+
Puppet server:
|
20
25
|
|
21
|
-
|
26
|
+
`/opt/puppetlabs/bin/puppetserver gem install hiera-mysql-json-backend-jruby jdbc-mysql`
|
22
27
|
|
23
|
-
|
28
|
+
### Configuring hiera
|
24
29
|
|
25
|
-
|
30
|
+
The backend is configured like any other in the hiera.conf. Here is the
|
31
|
+
simplest possible example:
|
26
32
|
|
27
33
|
```yaml
|
28
34
|
---
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
:
|
35
|
-
|
35
|
+
:backends:
|
36
|
+
- yaml
|
37
|
+
- mysql_json
|
38
|
+
|
39
|
+
:yaml:
|
40
|
+
:datadir: /etc/puppet/hieradata
|
41
|
+
|
42
|
+
:mysql_json:
|
43
|
+
:datadir: /etc/puppet/hieradata
|
36
44
|
|
37
|
-
|
38
|
-
|
45
|
+
:hierarchy:
|
46
|
+
- "%{::clientcert}"
|
47
|
+
- "%{::custom_location}"
|
48
|
+
- common
|
49
|
+
|
50
|
+
:logger: console
|
39
51
|
```
|
40
52
|
|
41
|
-
|
53
|
+
This will cause it to try to connect on localhost:3306 with no username and
|
54
|
+
password. This will probably not work. The following options can be set:
|
42
55
|
|
43
|
-
|
56
|
+
* `host`: mysql host (string)
|
57
|
+
* `port`: mysql port (int)
|
58
|
+
* `user`: mysql user (string)
|
59
|
+
* `pass`: mysql password (string)
|
60
|
+
* `database`: mysql database name (string)
|
61
|
+
* `datadir`: root of your `mysql_json` hierarchy (string)
|
62
|
+
* `only_for`: only perform queries if conditions in this section are met (hash)
|
63
|
+
* `ignore_json_parse_errors`: Do not raise an exception when the database
|
64
|
+
contains invalid json (boolean, defaults to false)
|
44
65
|
|
45
|
-
|
66
|
+
A more complete example might contain:
|
46
67
|
|
68
|
+
```yaml
|
69
|
+
:mysql_json:
|
70
|
+
:datadir: /etc/puppet/hierasql
|
71
|
+
:host: db042.example.com
|
72
|
+
:user: puppetserver
|
73
|
+
:pass: secret123
|
74
|
+
:port: 3306
|
75
|
+
:ignore_json_parse_errors: true # why why why...
|
76
|
+
:only_for:
|
77
|
+
:fqdn:
|
78
|
+
- '^vagrant.+'
|
79
|
+
- '^node\d+\.someservice\.example\.com$'
|
80
|
+
:domain:
|
81
|
+
- '^vagrant.+
|
47
82
|
|
48
|
-
|
83
|
+
```
|
49
84
|
|
50
|
-
|
85
|
+
This will perform lookups if any of the given conditions are met:
|
51
86
|
|
87
|
+
* The nodes fqdn fact starts with 'vagrant'
|
88
|
+
* The nodes fqdn fact looks like node01.someservice.example.com
|
89
|
+
* The nodes domain fact starts with 'vagrant'
|
52
90
|
|
53
|
-
|
91
|
+
Any node fact may be used to build these conditions.
|
54
92
|
|
55
|
-
|
93
|
+
Note that putting something in the list that always matches makes the whole
|
94
|
+
`only_for` block useless.
|
56
95
|
|
57
|
-
|
58
|
-
---
|
59
|
-
:backends:
|
60
|
-
- yaml
|
61
|
-
- mysql2
|
96
|
+
### Defining queries
|
62
97
|
|
63
|
-
|
64
|
-
|
98
|
+
Queries are defined in he poorly named sql files. These are really yaml files
|
99
|
+
where the key is the lookup key and the value is the SQL statement (it accepts
|
100
|
+
interpolation)
|
65
101
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
:pass: password
|
71
|
-
:database: database
|
72
|
-
:port: 3306
|
102
|
+
As of version 0.0.4 you can also add connection information to these sql files,
|
103
|
+
this allows you to connect to different databases. This is optional if no
|
104
|
+
connection information is found it will use the default defined in your
|
105
|
+
hiera.yaml config.
|
73
106
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
- common
|
107
|
+
Lets assume your _datadir_ is `/etc/puppet/hieradata/` and your hierarchy for
|
108
|
+
hiera just have a common. hiera-mysql-backend would look for
|
109
|
+
/etc/puppet/hieradata/common.sql the common.sql would look like:
|
78
110
|
|
79
|
-
|
111
|
+
```yaml
|
112
|
+
---
|
113
|
+
# This is optional, if not present it will use the default connection info from hiera.yaml
|
114
|
+
:dbconfig:
|
115
|
+
:host: database.example.com
|
116
|
+
:user: hieratest
|
117
|
+
:pass: sekret
|
118
|
+
:database: testhieradb
|
119
|
+
:port: 44445
|
120
|
+
|
121
|
+
applications: SELECT value FROM applications WHERE host='%{fqdn}';
|
80
122
|
```
|
81
123
|
|
82
124
|
If `host` is not defined it will use `localhost` as default.
|
83
125
|
|
84
126
|
If `port` is not defined it will use the default `3306` mysql port
|
85
127
|
|
128
|
+
Running `hiera applications` would run the query against the configured
|
129
|
+
database, parse the result as json and return the resulting data structure. If
|
130
|
+
all you want is a string, strings are valid json, too.
|
131
|
+
|
132
|
+
|
133
|
+
### Error handling
|
134
|
+
|
135
|
+
When encountering invalid json, it will raise an exception, which would in turn
|
136
|
+
cause catalog compilation to fail. You can disable this behaviour by setting
|
137
|
+
`ignore_json_parse_errors`.
|
138
|
+
|
139
|
+
When no results are returned by your query, it will return nil.
|
140
|
+
|
141
|
+
When multiple results are returned by your query, it will return nil. A future
|
142
|
+
version will introduce `ignore_multiple_results`, defaulting to true, to make
|
143
|
+
it possible to trigger a catalog compilation in this case.
|
144
|
+
|
145
|
+
|
86
146
|
## Known issues
|
87
147
|
|
148
|
+
1. Multiple results are currently silently ignored.
|
88
149
|
1. It always return an Array of hashes regardless of the number of items returned. (I did this on purpose because it is what I needed but I may be persuaded to do otherwise)
|
89
150
|
2. This README is poorly written.
|
90
151
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "hiera-mysql-json-backend-jruby"
|
5
|
-
gem.version = "1.1.
|
5
|
+
gem.version = "1.1.1"
|
6
6
|
gem.authors = ["Hostnet"]
|
7
7
|
gem.email = ["opensource@hostnet.nl"]
|
8
8
|
gem.description = %q{Alternative MySQL backend with json support for hiera}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "hiera-mysql-json-backend"
|
5
|
-
gem.version = "1.1.
|
5
|
+
gem.version = "1.1.1"
|
6
6
|
gem.authors = ["Hostnet"]
|
7
7
|
gem.email = ["opensource@hostnet.nl"]
|
8
8
|
gem.description = %q{Alternative MySQL backend with json support for hiera}
|
@@ -25,7 +25,7 @@ class Hiera
|
|
25
25
|
return true unless constraints.is_a?(Hash)
|
26
26
|
should_lookup = false
|
27
27
|
constraints.each do |item, matchers|
|
28
|
-
next unless scope
|
28
|
+
next unless scope[item.to_s]
|
29
29
|
if scope[item.to_s] =~ compile_regexes(matchers)
|
30
30
|
should_lookup = true
|
31
31
|
break
|
@@ -85,7 +85,7 @@ class Hiera
|
|
85
85
|
new_answer = Backend.parse_answer(data[key], scope)
|
86
86
|
|
87
87
|
sql_results = query(connection_hash, new_answer)
|
88
|
-
|
88
|
+
# TODO: make sure we fail if we have more than 1 result, skip if less than 1.
|
89
89
|
next if sql_results.length != 1
|
90
90
|
begin
|
91
91
|
new_answer = JSON.parse(sql_results[0]['value'])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera-mysql-json-backend-jruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hostnet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jdbc-mysql
|