puppet_factset 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/lib/puppet_factset.rb +19 -0
- data/lib/puppet_factset/version.rb +1 -1
- 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: 48b580ff5dc4c047ca6e9440475f930e6d0a862e
|
4
|
+
data.tar.gz: ae9d7f14350fc87c0910fd3a16aa4b960b0aef8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13239c7af64c5e01953c285572b84eca39f47580721226a7b7aa65c6f0ecf8ed87eda76ce67f6923d227d028b5983b65dc434e7a27bf63cf1cf04f15fb002921
|
7
|
+
data.tar.gz: 4e33159277ce2e35c5a32270a65c5e3b0aa08a40a871e9f0d8968fc283b310655c29beae3caa9b37f04cb61061f8115417dd1b952d63eccb9074e79e8f31eb0d
|
data/README.md
CHANGED
@@ -71,6 +71,30 @@ factsets = PuppetFactset::factsets
|
|
71
71
|
|
72
72
|
* The `factsets` array will be sorted A-Z
|
73
73
|
|
74
|
+
## Merging additional facts/handling external facts
|
75
|
+
Sometimes you need to ensure that a fact is present without worrying to much about its real-world value, for example external facts or custom in-module facts that do things such as query for the system for package versions, etc.
|
76
|
+
|
77
|
+
`puppet_factset` will automatically merge the hiera data found in all `.json` files found inside the `spec/merge_facts` directory, relative to the current working directory into factset data for each OS when accessed via the above API (the factset files themselves are unchanged).
|
78
|
+
|
79
|
+
#### Worked example
|
80
|
+
|
81
|
+
```json
|
82
|
+
spec/merge_facts/extra_fact.json
|
83
|
+
{
|
84
|
+
"extra_fact": "hello"
|
85
|
+
}
|
86
|
+
```
|
87
|
+
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require 'puppet_factset'
|
91
|
+
fact_hash = PuppetFactset::factset_hash(system_name)
|
92
|
+
puts fact_hash["extra_fact"] # from your json file
|
93
|
+
puts fact_hash["osfamily"] # from the facts shipped inside this gem
|
94
|
+
```
|
95
|
+
|
96
|
+
Note that its possible to silently override shipped factsets using this method as well. I regard this as a feature.
|
97
|
+
|
74
98
|
## Development
|
75
99
|
|
76
100
|
* RSpec tests are provided, please ensure these pass before and after adding any ruby code to the project
|
data/lib/puppet_factset.rb
CHANGED
@@ -2,6 +2,9 @@ require "puppet_factset/version"
|
|
2
2
|
require "json"
|
3
3
|
|
4
4
|
module PuppetFactset
|
5
|
+
|
6
|
+
MERGE_FACTS_DIR = File.join("spec", "merge_facts")
|
7
|
+
|
5
8
|
# Return the name of the directory holding the factsets
|
6
9
|
def self.factset_dir
|
7
10
|
File.expand_path(File.join(File.dirname(__FILE__), '..', 'res', 'factset'))
|
@@ -11,6 +14,8 @@ module PuppetFactset
|
|
11
14
|
def self.factset_hash(factset_name)
|
12
15
|
data = JSON.parse(File.read(File.join(factset_dir(), "#{factset_name}.json")))
|
13
16
|
|
17
|
+
merge_facts(data["values"])
|
18
|
+
|
14
19
|
# The facts are tucked away inside the 'values' element so just return that
|
15
20
|
data["values"]
|
16
21
|
end
|
@@ -21,4 +26,18 @@ module PuppetFactset
|
|
21
26
|
File.basename(f).gsub('.json','')
|
22
27
|
}.sort
|
23
28
|
end
|
29
|
+
|
30
|
+
# If a directory exists at `merge_facts` relative to the current directory then
|
31
|
+
# all JSON files present in this directory will be loaded and merged into passed
|
32
|
+
# in factset
|
33
|
+
#
|
34
|
+
# @param factset Hash of facts (will be modified in-place)
|
35
|
+
def self.merge_facts(factset)
|
36
|
+
Dir["#{MERGE_FACTS_DIR}/*.json"].each { |json_file|
|
37
|
+
puts json_file
|
38
|
+
facts = JSON.parse(File.read(json_file))
|
39
|
+
puts facts
|
40
|
+
factset.merge!(facts)
|
41
|
+
}
|
42
|
+
end
|
24
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet_factset
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Williams
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-04-
|
13
|
+
date: 2017-04-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|