chef_handler_foreman 0.1.3 → 0.2.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 +32 -12
- data/lib/chef_handler_foreman/foreman_enc_fetcher.rb +43 -0
- data/lib/chef_handler_foreman/foreman_hooks.rb +13 -0
- data/lib/chef_handler_foreman/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce539aff97d68e13f443de93dc4743e970e3a9c9
|
4
|
+
data.tar.gz: 893d6305fb33e658ca007289985cbbe262d45fc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6491b945aa770d464b5e034854be6ea1491c11d9c3d669099133c974c589cee51f437160240291c33ebe08dfc77bed39b7d9779ed0f9b1a4341a5eb3e39de1d2
|
7
|
+
data.tar.gz: 4fac735f20e57ebdc0fd2b441e5d42f7711eb411418a5d079c2142407eee4fadde36280ce1e4258eed8f638cd307b28b64a52eb15dda8c5bfb8b9022dfa35a95
|
data/README.md
CHANGED
@@ -35,6 +35,10 @@ foreman_facts_cache_file '/var/cache/chef_foreman_cache.md5'
|
|
35
35
|
foreman_reports_upload true
|
36
36
|
# add following line to manage reports verbosity. Allowed values are debug, notice and error
|
37
37
|
reports_log_level "notice"
|
38
|
+
# add following line to load additional attributes from Foreman
|
39
|
+
foreman_enc true
|
40
|
+
# to configure the level of attributes coming from Foreman you can set a second argument like this
|
41
|
+
foreman_enc true, 'default'
|
38
42
|
```
|
39
43
|
|
40
44
|
### Using Chef-Client Cookbook
|
@@ -48,6 +52,7 @@ With a Role
|
|
48
52
|
"chef_server_url": "https://chef.domain.com",
|
49
53
|
"config": {
|
50
54
|
"foreman_server_url": "https://foreman.domain.com",
|
55
|
+
"foreman_enc": true,
|
51
56
|
"foreman_facts_upload": true,
|
52
57
|
"foreman_reports_upload": true,
|
53
58
|
"reports_log_level": "notice"
|
@@ -64,28 +69,17 @@ node['chef_client']['config']['foreman_reports_upload'] = true
|
|
64
69
|
node['chef_client']['config']['reports_log_level'] = 'notice'
|
65
70
|
```
|
66
71
|
|
67
|
-
|
68
72
|
You can also specify a second argument to foreman_reports_upload which is a number:
|
69
73
|
- 1 (default) for reporter based on more detailed ResourceReporter
|
70
74
|
- 2 not so verbose based just on run_status, actually just counts applied resources
|
71
75
|
|
72
|
-
## Chef 10 support
|
73
|
-
|
74
|
-
Chef 10 is generally supported from version 0.0.6 and above. However you must set
|
75
|
-
foreman_reports_upload mode to 2 manually. We can't get detailed reports in old
|
76
|
-
chef. The configuration line will look like this:
|
77
|
-
|
78
|
-
```ruby
|
79
|
-
foreman_reports_upload true, 2
|
80
|
-
```
|
81
|
-
|
82
76
|
### Caching of facts
|
83
77
|
|
84
78
|
Note that some attributes, such as network counters or used memory, change on every chef-client run.
|
85
79
|
For caching to work, you would need to blacklist such attributes, otherwise facts will be uploaded
|
86
80
|
on every run.
|
87
81
|
|
88
|
-
|
82
|
+
### Facts whitelisting / blacklisting
|
89
83
|
|
90
84
|
Cherry picking which facts to upload, coupled with caching, allows to scale the solution to many
|
91
85
|
thousands of nodes. Note, however, that some attributes are expected by Foreman to exist, and thus
|
@@ -95,3 +89,29 @@ attributes known to work in a large scale production environment.
|
|
95
89
|
Note that the order of config options matter. Blacklist/whitelist must be below foreman_facts_upload
|
96
90
|
line.
|
97
91
|
|
92
|
+
### Loading attribute from Foreman
|
93
|
+
|
94
|
+
Since version 0.2.0, you can also load node attributes from Foreman. This requires smart_proxy_chef
|
95
|
+
plugin version 0.2.0 as well. Attributes loaded from Foreman will be merged to those coming form
|
96
|
+
chef-server. You can optionally set on which level they will be injected. Available values are:
|
97
|
+
|
98
|
+
* default
|
99
|
+
* force_default
|
100
|
+
* normal
|
101
|
+
* override
|
102
|
+
* force_override
|
103
|
+
* automatic
|
104
|
+
|
105
|
+
If chef attribute and Foreman parameter have the same name, the priority based on levels
|
106
|
+
above will determine, which will override the other one. A default level is force_default,
|
107
|
+
so you can override only default attributes from Foreman.
|
108
|
+
|
109
|
+
## Chef 10 support
|
110
|
+
|
111
|
+
Chef 10 is generally supported from version 0.0.6 and above. However you must set
|
112
|
+
foreman_reports_upload mode to 2 manually. We can't get detailed reports in old
|
113
|
+
chef. The configuration line will look like this:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
foreman_reports_upload true, 2
|
117
|
+
```
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module ChefHandlerForeman
|
4
|
+
class ForemanEncFetcher < ::Chef::EventDispatch::Base
|
5
|
+
SUPPORTED_LEVELS = %w(default force_default normal override force_override automatic)
|
6
|
+
|
7
|
+
attr_accessor :uploader
|
8
|
+
|
9
|
+
def initialize(level)
|
10
|
+
super()
|
11
|
+
raise "Unsupported node attributes level #{level}, use one of #{SUPPORTED_LEVELS.join(', ')}" unless SUPPORTED_LEVELS.include?(level)
|
12
|
+
@attributes_level = level
|
13
|
+
end
|
14
|
+
|
15
|
+
def node_load_completed(node)
|
16
|
+
client_name = node.name
|
17
|
+
result = Chef::Config.foreman_uploader.foreman_request("/api/enc/#{client_name}", client_name, client_name, 'get')
|
18
|
+
begin
|
19
|
+
enc = JSON.parse(result.body)
|
20
|
+
rescue => e
|
21
|
+
Chef::Log.error "Foreman ENC could not be fetched because of #{e.class}: #{e.message}"
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
|
25
|
+
enc['parameters'].each do |parameter, value|
|
26
|
+
nested_parts = parameter.split('::')
|
27
|
+
nest = nested_parts[0..-2].inject(node.send(@attributes_level)) { |attributes_nest, attribute| attributes_nest[attribute] }
|
28
|
+
nest[nested_parts[-1]] = type_cast(value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def type_cast(value)
|
33
|
+
case value
|
34
|
+
when 'false'
|
35
|
+
false
|
36
|
+
when 'true'
|
37
|
+
true
|
38
|
+
else
|
39
|
+
value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -4,6 +4,7 @@ require "#{File.dirname(__FILE__)}/foreman_reporting"
|
|
4
4
|
# this reporter is supported in chef 11 or later
|
5
5
|
unless Gem::Version.new(Chef::VERSION) < Gem::Version.new('11.0.0')
|
6
6
|
require "#{File.dirname(__FILE__)}/foreman_resource_reporter"
|
7
|
+
require "#{File.dirname(__FILE__)}/foreman_enc_fetcher"
|
7
8
|
end
|
8
9
|
|
9
10
|
require "#{File.dirname(__FILE__)}/foreman_uploader"
|
@@ -78,6 +79,18 @@ module ChefHandlerForeman
|
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
82
|
+
def foreman_enc(enc, level = 'force_default')
|
83
|
+
if enc
|
84
|
+
@foreman_enc_fetcher = ForemanEncFetcher.new(level)
|
85
|
+
@foreman_enc_fetcher.uploader = @foreman_uploader
|
86
|
+
if Chef::Config[:event_handlers].is_a?(Array)
|
87
|
+
Chef::Config[:event_handlers].push @foreman_enc_fetcher
|
88
|
+
else
|
89
|
+
Chef::Config[:event_handlers] = [@foreman_enc_fetcher]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
81
94
|
# level can be string error notice debug
|
82
95
|
def reports_log_level(level)
|
83
96
|
raise ArgumentError, 'unknown level: ' + level.to_s unless %w(error notice debug).include?(level)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef_handler_foreman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marek Hulan
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
51
|
- lib/chef_handler_foreman.rb
|
52
|
+
- lib/chef_handler_foreman/foreman_enc_fetcher.rb
|
52
53
|
- lib/chef_handler_foreman/foreman_facts.rb
|
53
54
|
- lib/chef_handler_foreman/foreman_hooks.rb
|
54
55
|
- lib/chef_handler_foreman/foreman_reporting.rb
|