minimal-diff-chef-formatter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +54 -0
- data/lib/minimal-diff-chef-formatter.rb +248 -0
- data/minimal-diff-chef-formatter.gemspec +18 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df15d16527e8b79e0810b6512398d9b145aba2f7
|
4
|
+
data.tar.gz: fa40bc8ec40866a4644d58b2538bd52ed6c472a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d807c2a4535d321adace9e181730278e858a9e44c9ac37bfc453629e8d5253d85324f5a9a54c50a5a07388573c35eeb655320773d33b046447a5a90c6932c0cd
|
7
|
+
data.tar.gz: db0a4e3cc2924b778ea130d35b8c9cddcb5112249fdadbac57c6168816b76a09cb2dd9e474a3326ffe8a71270bff4b32b1e8d3d1fc3726d86de11baf4a5649af
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
Minimal-diff formatter
|
2
|
+
======================
|
3
|
+
|
4
|
+
A formatter for [Chef](http://getchef.com) to keep the output of chef-client
|
5
|
+
as small as possible. Unlike default minimal formatter it shows more info about
|
6
|
+
updated resources.
|
7
|
+
|
8
|
+
This formatter will display the total number of processed resources, as the
|
9
|
+
number of unchanged, updated and failed resources.
|
10
|
+
|
11
|
+
This is inspired by [Nyan Cat <3 Chef Formatter](https://github.com/andreacampi/nyan-cat-chef-formatter).
|
12
|
+
Actually no, scratch that: this is basically a ripoff. So sue me second after @andreacampi.
|
13
|
+
|
14
|
+
Usage
|
15
|
+
=====
|
16
|
+
|
17
|
+
Install the gem:
|
18
|
+
|
19
|
+
gem install minimal-diff-chef-formatter
|
20
|
+
|
21
|
+
If you are using Omnibus Chef you need to specify the full path to the `gem`
|
22
|
+
binary:
|
23
|
+
|
24
|
+
/opt/chef/embedded/bin/gem install minimal-diff-chef-formatter
|
25
|
+
|
26
|
+
Or write a cookbook to install it using the `chef_gem` resource, if that's
|
27
|
+
how you roll. See http://community.opscode.com/cookbooks/nyan-cat for inspiration.
|
28
|
+
|
29
|
+
Then add the following to your `/etc/chef/client.rb` file:
|
30
|
+
|
31
|
+
gem 'minimal-diff-chef-formatter'
|
32
|
+
require 'minimal-diff-chef-formatter'
|
33
|
+
|
34
|
+
This enables the formatter, but doesn't use it by default. To see Nyan in all its
|
35
|
+
glory, run:
|
36
|
+
|
37
|
+
chef-client -Fmindiff -lfatal
|
38
|
+
|
39
|
+
Enjoy!
|
40
|
+
|
41
|
+
For serious Nyan addicts only!
|
42
|
+
------------------------------
|
43
|
+
|
44
|
+
To enable the Nyan formatter by default, add the following line to
|
45
|
+
`/etc/chef/client.rb`:
|
46
|
+
|
47
|
+
formatter :mindiff
|
48
|
+
|
49
|
+
|
50
|
+
Author
|
51
|
+
----------
|
52
|
+
[Vyacheslav Kuznetsov](https://www.github.com/smith3v) :: @smith3v
|
53
|
+
[Andrea Campi](https://www.github.com/andreacampi) :: @andreacampi
|
54
|
+
[Matt Sears](https://wwww.mattsears.com) :: @mattsears
|
@@ -0,0 +1,248 @@
|
|
1
|
+
require 'chef/formatters/base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
|
5
|
+
module Formatters
|
6
|
+
|
7
|
+
|
8
|
+
# == Formatters::MinimalDiff
|
9
|
+
# Shows the progress of the chef run by printing single characters, and
|
10
|
+
# displays a summary of updates at the conclusion of the run. For events
|
11
|
+
# that don't have meaningful status information (loading a file, syncing a
|
12
|
+
# cookbook) a dot is printed. For resources, a dot, 'S' or 'U' is printed
|
13
|
+
# if the resource is up to date, skipped by not_if/only_if, or updated,
|
14
|
+
# respectively.
|
15
|
+
|
16
|
+
#Unlike the Formatters::Minimal it shows diff for updated resources.
|
17
|
+
|
18
|
+
class MinimalDiff < Formatters::Base
|
19
|
+
|
20
|
+
cli_name(:mindiff)
|
21
|
+
|
22
|
+
attr_reader :updated_resources
|
23
|
+
attr_reader :updates_by_resource
|
24
|
+
|
25
|
+
|
26
|
+
def initialize(out, err)
|
27
|
+
super
|
28
|
+
@updated_resources = []
|
29
|
+
@updates_by_resource = Hash.new {|h, k| h[k] = []}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Called at the very start of a Chef Run
|
33
|
+
def run_start(version)
|
34
|
+
puts "Starting Chef Client, version #{version}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Called at the end of the Chef run.
|
38
|
+
def run_completed(node)
|
39
|
+
puts "chef client finished, #{@updated_resources.size} resources updated"
|
40
|
+
end
|
41
|
+
|
42
|
+
# called at the end of a failed run
|
43
|
+
def run_failed(exception)
|
44
|
+
puts "chef client failed. #{@updated_resources.size} resources updated"
|
45
|
+
end
|
46
|
+
|
47
|
+
# Called right after ohai runs.
|
48
|
+
def ohai_completed(node)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Already have a client key, assuming this node has registered.
|
52
|
+
def skipping_registration(node_name, config)
|
53
|
+
end
|
54
|
+
|
55
|
+
# About to attempt to register as +node_name+
|
56
|
+
def registration_start(node_name, config)
|
57
|
+
end
|
58
|
+
|
59
|
+
def registration_completed
|
60
|
+
end
|
61
|
+
|
62
|
+
# Failed to register this client with the server.
|
63
|
+
def registration_failed(node_name, exception, config)
|
64
|
+
super
|
65
|
+
end
|
66
|
+
|
67
|
+
def node_load_start(node_name, config)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Failed to load node data from the server
|
71
|
+
def node_load_failed(node_name, exception, config)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Default and override attrs from roles have been computed, but not yet applied.
|
75
|
+
# Normal attrs from JSON have been added to the node.
|
76
|
+
def node_load_completed(node, expanded_run_list, config)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Called before the cookbook collection is fetched from the server.
|
80
|
+
def cookbook_resolution_start(expanded_run_list)
|
81
|
+
puts "resolving cookbooks for run list: #{expanded_run_list.inspect}"
|
82
|
+
end
|
83
|
+
|
84
|
+
# Called when there is an error getting the cookbook collection from the
|
85
|
+
# server.
|
86
|
+
def cookbook_resolution_failed(expanded_run_list, exception)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Called when the cookbook collection is returned from the server.
|
90
|
+
def cookbook_resolution_complete(cookbook_collection)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Called before unneeded cookbooks are removed
|
94
|
+
#--
|
95
|
+
# TODO: Should be called in CookbookVersion.sync_cookbooks
|
96
|
+
def cookbook_clean_start
|
97
|
+
end
|
98
|
+
|
99
|
+
# Called after the file at +path+ is removed. It may be removed if the
|
100
|
+
# cookbook containing it was removed from the run list, or if the file was
|
101
|
+
# removed from the cookbook.
|
102
|
+
def removed_cookbook_file(path)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Called when cookbook cleaning is finished.
|
106
|
+
def cookbook_clean_complete
|
107
|
+
end
|
108
|
+
|
109
|
+
# Called before cookbook sync starts
|
110
|
+
def cookbook_sync_start(cookbook_count)
|
111
|
+
puts "Synchronizing cookbooks"
|
112
|
+
end
|
113
|
+
|
114
|
+
# Called when cookbook +cookbook_name+ has been sync'd
|
115
|
+
def synchronized_cookbook(cookbook_name)
|
116
|
+
print "."
|
117
|
+
end
|
118
|
+
|
119
|
+
# Called when an individual file in a cookbook has been updated
|
120
|
+
def updated_cookbook_file(cookbook_name, path)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Called after all cookbooks have been sync'd.
|
124
|
+
def cookbook_sync_complete
|
125
|
+
puts "done."
|
126
|
+
end
|
127
|
+
|
128
|
+
# Called when cookbook loading starts.
|
129
|
+
def library_load_start(file_count)
|
130
|
+
puts "Compiling cookbooks"
|
131
|
+
end
|
132
|
+
|
133
|
+
# Called after a file in a cookbook is loaded.
|
134
|
+
def file_loaded(path)
|
135
|
+
print '.'
|
136
|
+
end
|
137
|
+
|
138
|
+
def file_load_failed(path, exception)
|
139
|
+
super
|
140
|
+
end
|
141
|
+
|
142
|
+
# Called when recipes have been loaded.
|
143
|
+
def recipe_load_complete
|
144
|
+
puts "done."
|
145
|
+
end
|
146
|
+
|
147
|
+
# Called before convergence starts
|
148
|
+
def converge_start(run_context)
|
149
|
+
puts "Converging #{run_context.resource_collection.all_resources.size} resources"
|
150
|
+
end
|
151
|
+
|
152
|
+
# Called when the converge phase is finished.
|
153
|
+
def converge_complete
|
154
|
+
puts "\n"
|
155
|
+
puts "System converged."
|
156
|
+
if updated_resources.empty?
|
157
|
+
puts "no resources updated"
|
158
|
+
else
|
159
|
+
puts "\n"
|
160
|
+
puts "resources updated this run:"
|
161
|
+
updated_resources.each do |resource|
|
162
|
+
puts "* #{resource.to_s}"
|
163
|
+
updates_by_resource[resource.name].flatten.each do |update|
|
164
|
+
puts " #{update}"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# Called before action is executed on a resource.
|
171
|
+
def resource_action_start(resource, action, notification_type=nil, notifier=nil)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Called when a resource fails, but will retry.
|
175
|
+
def resource_failed_retriable(resource, action, retry_count, exception)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Called when a resource fails and will not be retried.
|
179
|
+
def resource_failed(resource, action, exception)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Called when a resource action has been skipped b/c of a conditional
|
183
|
+
def resource_skipped(resource, action, conditional)
|
184
|
+
print "S"
|
185
|
+
end
|
186
|
+
|
187
|
+
# Called after #load_current_resource has run.
|
188
|
+
def resource_current_state_loaded(resource, action, current_resource)
|
189
|
+
end
|
190
|
+
|
191
|
+
# Called when a resource has no converge actions, e.g., it was already correct.
|
192
|
+
def resource_up_to_date(resource, action)
|
193
|
+
print "."
|
194
|
+
end
|
195
|
+
|
196
|
+
## TODO: callback for assertion failures
|
197
|
+
|
198
|
+
## TODO: callback for assertion fallback in why run
|
199
|
+
|
200
|
+
# Called when a change has been made to a resource. May be called multiple
|
201
|
+
# times per resource, e.g., a file may have its content updated, and then
|
202
|
+
# its permissions updated.
|
203
|
+
def resource_update_applied(resource, action, update)
|
204
|
+
prefix = Chef::Config[:why_run] ? "Would " : ""
|
205
|
+
Array(update).each do |line|
|
206
|
+
next if line.nil?
|
207
|
+
if line.kind_of? String
|
208
|
+
@updates_by_resource[resource.name] << " - #{prefix}#{line}"
|
209
|
+
elsif line.kind_of? Array
|
210
|
+
# Expanded output - delta
|
211
|
+
# @todo should we have a resource_update_delta callback?
|
212
|
+
line.each do |detail|
|
213
|
+
@updates_by_resource[resource.name] << " #{detail}"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
# Called after a resource has been completely converged.
|
220
|
+
def resource_updated(resource, action)
|
221
|
+
updated_resources << resource
|
222
|
+
print "U"
|
223
|
+
end
|
224
|
+
|
225
|
+
# Called before handlers run
|
226
|
+
def handlers_start(handler_count)
|
227
|
+
end
|
228
|
+
|
229
|
+
# Called after an individual handler has run
|
230
|
+
def handler_executed(handler)
|
231
|
+
end
|
232
|
+
|
233
|
+
# Called after all handlers have executed
|
234
|
+
def handlers_completed
|
235
|
+
end
|
236
|
+
|
237
|
+
# An uncategorized message. This supports the case that a user needs to
|
238
|
+
# pass output that doesn't fit into one of the callbacks above. Note that
|
239
|
+
# there's no semantic information about the content or importance of the
|
240
|
+
# message. That means that if you're using this too often, you should add a
|
241
|
+
# callback for it.
|
242
|
+
def msg(message)
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "minimal-diff-chef-formatter"
|
5
|
+
s.version = "0.1.0"
|
6
|
+
s.authors = ["Vyacheslav Kuznetsov"]
|
7
|
+
s.email = ["kuznetsovvv@gmail.com"]
|
8
|
+
s.homepage = "https://github.com/smith3v/minimal-diff-chef-formatter"
|
9
|
+
s.summary = %q{Minimal Chef formatter with diffs}
|
10
|
+
s.description = %q{Minimal Chef formatter with diffs}
|
11
|
+
|
12
|
+
s.rubyforge_project = "minimal-diff-chef-formatter"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minimal-diff-chef-formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vyacheslav Kuznetsov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Minimal Chef formatter with diffs
|
14
|
+
email:
|
15
|
+
- kuznetsovvv@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- lib/minimal-diff-chef-formatter.rb
|
22
|
+
- minimal-diff-chef-formatter.gemspec
|
23
|
+
homepage: https://github.com/smith3v/minimal-diff-chef-formatter
|
24
|
+
licenses: []
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project: minimal-diff-chef-formatter
|
42
|
+
rubygems_version: 2.2.0
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Minimal Chef formatter with diffs
|
46
|
+
test_files: []
|